From c24fa4f72993ee18c993f7ba137cc7fcd406d887 Mon Sep 17 00:00:00 2001 From: Matthias Neid Date: Thu, 17 Aug 2023 11:00:54 +0200 Subject: [PATCH 1/3] added special case for handling php 8.1.22/8.2.9 --- src/Pool.php | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Pool.php b/src/Pool.php index 4bd650f..91ee6d3 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -306,6 +306,18 @@ protected function registerListener() pcntl_async_signals(true); pcntl_signal(SIGCHLD, function ($signo, $status) { + /** + * PHP 8.1.22 and 8.2.9 fixed SIGCHLD handling: + * https://github.com/php/php-src/pull/11509 + * This breaks 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']); + } + while (true) { $pid = pcntl_waitpid(-1, $processState, WNOHANG | WUNTRACED); @@ -313,21 +325,24 @@ 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); + return; + } - $this->markAsFailed($process); - } - }); + $this->markAsFailed($process); } public function stop() From 1a4bb218670a3c606738615b9a0decd5fdc3f591 Mon Sep 17 00:00:00 2001 From: Matthias Neid Date: Thu, 17 Aug 2023 11:14:19 +0200 Subject: [PATCH 2/3] return after handling php 8.1.22/8.2.9 --- src/Pool.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Pool.php b/src/Pool.php index 91ee6d3..8fce68d 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -307,15 +307,16 @@ protected function registerListener() pcntl_signal(SIGCHLD, function ($signo, $status) { /** - * PHP 8.1.22 and 8.2.9 fixed SIGCHLD handling: + * PHP 8.1.22 and 8.2.9 changed SIGCHLD handling: * https://github.com/php/php-src/pull/11509 - * This breaks pcntl_waitpid() at the same time, so it requires special handling. + * 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) { From d10fccc0462bfe92c616e8021fd127fd1ec40de3 Mon Sep 17 00:00:00 2001 From: matthi4s Date: Thu, 17 Aug 2023 09:14:42 +0000 Subject: [PATCH 3/3] Fix styling --- src/Pool.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Pool.php b/src/Pool.php index 8fce68d..3149e76 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -316,6 +316,7 @@ protected function registerListener() */ if (phpversion() === '8.1.22' || phpversion() === '8.2.9') { $this->handleFinishedProcess($status['pid'], $status['status']); + return; } @@ -331,15 +332,17 @@ protected function registerListener() }); } - protected function handleFinishedProcess(int $pid, int $status) { + protected function handleFinishedProcess(int $pid, int $status) + { $process = $this->inProgress[$pid] ?? null; - if (!$process) { + if (! $process) { return; } if ($status === 0) { $this->markAsFinished($process); + return; }