workerman中调用pcntl_fork 实现多进程时,无法回收子进程问题

leojen

$pid = pcntl_fork();
//父进程和子进程都会执行下面代码
if ($pid == -1) {
//错误处理:创建子进程失败时返回-1.
die('could not fork');
} else if ($pid) {
//父进程会得到子进程号,所以这里是父进程执行的逻辑
pcntl_wait($status); //等待子进程中断,防止子进程成为僵尸进程。
} else {

 //子进程逻辑
 exit()

}

如上,正常情况下 子进程逻辑结束之后,需要手动调用exit结束子进程。
但是现在的问题是,在workerman里不能手动调用 exit(),否则会造成整个进程退出。
但是不调用的话,没法手动结束子进程,并且会报错:
process_timeout:

1 /home/hero/workspace/php/hero_data/vendor/workerman/workerman/Events/Select.php(261): pcntl_signal_dispatch()

2 /home/hero/workspace/php/hero_data/vendor/workerman/workerman/Worker.php(2430): Workerman\Events\Select->loop()

3 /home/hero/workspace/php/hero_data/vendor/workerman/gateway-worker/src/BusinessWorker.php(197): Workerman\Worker->run()

4 /home/hero/workspace/php/hero_data/vendor/workerman/workerman/Worker.php(1554): GatewayWorker\BusinessWorker->run()

5 /home/hero/workspace/php/hero_data/vendor/workerman/workerman/Worker.php(1384): Workerman\Worker::forkOneWorkerForLinux(Object(GatewayWorker\BusinessWorker))

6 /home/hero/workspace/php/hero_data/vendor/workerman/workerman/Worker.php(1358): Workerman\Worker::forkWorkersForLinux()

7 /home/hero/workspace/php/hero_data/vendor/workerman/workerman/Worker.php(542): Workerman\Worker::forkWorkers()

8 /home/hero/workspace/php/hero_data/application/command/SupportCenter.php(82): Workerman\Worker::runAll()

9 /home/hero/workspace/php/hero_data/thinkphp/library/think/console/Command.php(175): app\command\SupportCenter->execute(Object(think\console\Input), Object(think\console\Output))

10 /home/hero/workspace/php/hero_data/thinkphp/library/think/Console.php(675): think\console\Command->run(Object(think\console\Input), Object(think\console\Output))

11 /home/hero/workspace/php/hero_data/thinkphp/library/think/Console.php(261): think\Console->doRunCommand(Object(app\command\SupportCenter), Object(think\console\Input), Object(think\console\Output))

12 /home/hero/workspace/php/hero_data/thinkphp/library/think/Console.php(198): think\Console->doRun(Object(think\console\Input), Object(think\console\Output))

13 /home/hero/workspace/php/hero_data/thinkphp/library/think/Console.php(115): think\Console->run()

怎么解。。求助。。

2691 1 0
1个回答

walkor 打赏

workerman不支持业务调用pcntl_fork,尤其是使用了event扩展的情况下。

年代过于久远,无法发表回答
×
🔝