$workers = [];
$worker_num = 3;//创建的进程数
for($i=0;$i<$worker_num ; $i++){
$process = new swoole_process('process');// 创建子进程 启动函数为 process
$pid = $process->start();// 子进程启动
$workers[$pid] = $process;// 存入字符数组
}
foreach($workers as $process){
//子进程会包含此事件,加入到子进程中 异步IO
swoole_event_add($process->pipe, function ($pipe) use($process){
$data = $process->read();
echo "RECV: " . $data.PHP_EOL;// 接收数据
});//函数调用的神奇情况
}
function process(swoole_process $process){// 第一个处理
$process->write("processId:".$process->pid);// 子进程写入信息到管道。
echo "echo:".$process->pid."\t".$process->callback .PHP_EOL;// 打印提示信息结果 及制表符
}