function spawn($exec, $args = array()) {
$pid = pcntl_fork();
if ($pid < 0)
return false;
else if ($pid == 0) {
$ppid = getmypid();
$pid = pcntl_fork();
if ($pid < 0)
file_put_contents('/tmp/error.log', "fork failed: ${cmd} ". implode(' ', $args). "\n");
else if ($pid == 0) {
pcntl_waitpid($ppid, $status);
pcntl_exec($exec, $args);
}
else
exit(0);
}
}
这在 CLI 模式下运行良好。但是对于 php-fpm,它会导致调用者死循环,然后超时。为什么会发生这种情况?