Skip to content
This repository was archived by the owner on Dec 16, 2019. It is now read-only.
This repository was archived by the owner on Dec 16, 2019. It is now read-only.

php-zts with pthreads not allocating tasks to free workers #941

Description

@blacktek

Hi,
I've the same problem reported here:
https://stackoverflow.com/questions/54217345/php-multi-threading-and-pools

Basically I've php 7.2.19 with zts enabled:
[root@server tmp]# php -i | grep -i thread
/etc/php-zts.d/pthreads.ini
Thread Safety => enabled
pthreads

[root@server tmp]# php -v
PHP 7.2.19 (cli) (built: May 29 2019 11:10:45) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.19, Copyright (c) 1999-2018, by Zend Technologies

I've the same problem both on Windows10 and CentOS7, so it's not OS related.

If I run this code:


$pool = new Pool(2);
foreach ([0,1,2,3] as $count) {
$pool->submit(
new class ($count) extends Threaded
{
private $count;

        public function __construct(int $count)
        {
            $this->count= $count;
        }

        public function run()
        {
            if ($this->count== 0) {
                sleep(3);
                echo $this->count . " is ready\n";
            } else {
                echo $this->count . " is ready\n";
            }
        }
    }
);

}

while ($pool->collect());

$pool->shutdown();

I get as output:
1 is ready
3 is ready
0 is ready
2 is ready

While I would expect that "0 is ready" is printed as last row, because "2 is ready" should be worked by first Worker not doing the sleep.

Where is the mistake and how to create a real POOL model where there are not free workers while there are tasks in queue?

Thank you

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions