Skip to content

Commit

Permalink
Merge pull request #212 from matthi4s/master
Browse files Browse the repository at this point in the history
Fix finished process handling in PHP 8.1.22/8.2.9
  • Loading branch information
AlexVanderbist authored Aug 25, 2023
2 parents 1babcf0 + d10fccc commit 24a8ffa
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,28 +310,47 @@ 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);

if ($pid <= 0) {
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()
Expand Down

0 comments on commit 24a8ffa

Please sign in to comment.