Php 分叉时缺少_destruct的最终调用
今天我遇到了PHP的一些奇怪行为: 分叉时,每个子级都会触发一个_destruct函数,这是它们应该触发的,但在最后一个子级完成后,父级不再调用_destruct 我的代码:Php 分叉时缺少_destruct的最终调用,php,destructor,fork,Php,Destructor,Fork,今天我遇到了PHP的一些奇怪行为: 分叉时,每个子级都会触发一个_destruct函数,这是它们应该触发的,但在最后一个子级完成后,父级不再调用_destruct 我的代码: class Test { public function __construct() { for ($i = 0; $i < 4; $i++) { $pid = pcntl_fork(); if (!$pid) {
class Test {
public function __construct() {
for ($i = 0; $i < 4; $i++) {
$pid = pcntl_fork();
if (!$pid) {
print("child ".$i."\n");
exit($i);
}
while (pcntl_waitpid(0, $status) != -1) {
$status = pcntl_wexitstatus($status);
print("child ".$status." finished\n");
}
print("parent still alive\n");
}
}
public function __destruct() {
print("destruct\n");
}
}
我怎样才能解决这个问题?我做错了什么?哪个PHP版本?5.4.34和5.5.9在这里都可以正常工作,并调用最终销毁。您确定您的父进程实际完成了吗?没有其他代码?谢谢你的回答。我使用PHP5.5.9,分叉完成后,脚本处理一些其他代码。今晚我将发布我的全部代码,这只是一个简化的示例。
child 0
destruct
child 0 finished
child 1
destruct
child 1 finished
child 2
destruct
child 2 finished
child 3
destruct
child 3 finished
parent still alive