Last active
November 10, 2019 14:53
-
-
Save simPod/5a177947bdf864026bfc59d71d6e9d71 to your computer and use it in GitHub Desktop.
pcntl_waitpid() bug on 7.3 + ext-grpc macos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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