diff --git a/src/Pool.php b/src/Pool.php index ee7151f..424cfc9 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -310,6 +310,20 @@ protected function registerListener() pcntl_async_signals(true); pcntl_signal(SIGCHLD, function ($signo, $status) { + /** + * PHP 8.1.22 and 8.2.9 changed SIGCHLD handling: + * https://github.com/php/php-src/pull/11509 + * This changes pcntl_waitpid() at the same time, so it requires special handling. + * + * It was reverted already and probably won't work in any other PHP version. + * https://github.com/php/php-src/pull/11863 + */ + if (phpversion() === '8.1.22' || phpversion() === '8.2.9') { + $this->handleFinishedProcess($status['pid'], $status['status']); + + return; + } + while (true) { $pid = pcntl_waitpid(-1, $processState, WNOHANG | WUNTRACED); @@ -317,21 +331,26 @@ protected function registerListener() break; } - $process = $this->inProgress[$pid] ?? null; + $this->handleFinishedProcess($pid, $status['status']); + } + }); + } - if (! $process) { - continue; - } + protected function handleFinishedProcess(int $pid, int $status) + { + $process = $this->inProgress[$pid] ?? null; - if ($status['status'] === 0) { - $this->markAsFinished($process); + if (! $process) { + return; + } - continue; - } + if ($status === 0) { + $this->markAsFinished($process); - $this->markAsFailed($process); - } - }); + return; + } + + $this->markAsFailed($process); } public function stop()