Skip to content

Commit 91b6b21

Browse files
committed
update async_master.php.
1 parent f0d4653 commit 91b6b21

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

examples/process/async_master.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@ function onReceive($pipe) {
88
global $workers;
99
$worker = $workers[$pipe];
1010
$data = $worker->read();
11-
if ($data == false)
12-
{
13-
//表示子进程已关闭,回收它
14-
$status = swoole_process::wait();
15-
echo "Worker#{$status['pid']} exit\n";
16-
}
17-
else
18-
{
19-
echo "RECV: ".$data;
20-
}
11+
echo "RECV: " . $data;
2112
}
2213

2314
//循环创建进程
@@ -37,6 +28,12 @@ function onReceive($pipe) {
3728
$workers[$process->pipe] = $process;
3829
}
3930

31+
swoole_process::signal(SIGCHLD, function(){
32+
//表示子进程已关闭,回收它
33+
$status = swoole_process::wait();
34+
echo "Worker#{$status['pid']} exit\n";
35+
});
36+
4037
//将子进程的管道加入EventLoop
4138
foreach($workers as $process)
4239
{

0 commit comments

Comments
 (0)