I'm trying to get Pthreads to work, but unfortunately with all of the outdated documentation it is really hard to figure out what is current and what has changed. As well as not getting any errors returned.
Running PHP7.2.0-dev with the latest version of pthreads and xDebug
Currently I have
<?php
$THREADS = 3;
class UptimeWorker extends Worker {
public function start(?int $options = null) {
return parent::start(PTHREADS_INHERIT_CLASSES | PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_FUNCTIONS);
}
}
class UptimeWork extends Threaded {
private $i;
public function __construct(int $i) {
$this->i = $i;
}
public function run() {
echo "I am ".$i.PHP_EOL;
$this->setGarbage();
}
}
$pool = new Pool($THREADS, UptimeWorker::class);
for($i=0;$i<10;$i++) {
var_dump($i);
$pool->submit(new UptimeWork($i));
}
echo "pre-shutdown".PHP_EOL;
$pool->shutdown();
echo "finished".PHP_EOL;
and the only output is int(0)
from the first var_dump
call in the for
statement, from there the process just seems to hang, it doesn't exit and no further output is given.
What is going wrong here and what needs to happen in order for this to work?