Skip to content

Instantly share code, notes, and snippets.

@simPod
Last active November 10, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simPod/5a177947bdf864026bfc59d71d6e9d71 to your computer and use it in GitHub Desktop.
Save simPod/5a177947bdf864026bfc59d71d6e9d71 to your computer and use it in GitHub Desktop.
pcntl_waitpid() bug on 7.3 + ext-grpc macos
<?php
declare(strict_types=1);
$childProcs = [];
for ($batch = 0; $batch < 1; $batch++) {
$pid = pcntl_fork();
if ($pid === -1) {
throw new RuntimeException('Failed to create child process');
}
if ($pid !== 0) {
$childProcs[] = [
'pid' => $pid,
];
} else {
echo 'Exiting child';
echo PHP_EOL;
exit(0);
}
}
while (count($childProcs) > 0) {
foreach ($childProcs as $key => $procData) {
$res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
if ($res === $procData['pid']) {
unset($childProcs[$key]);
echo 'unset child ' . $key;
echo PHP_EOL;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment