<?php $workers = [];//进程池 $worker_num = 3;//创建进程的数据量 for ($i = 0; $i<$worker_num;$i++){ $process = new swoole_process('doProcess');//创建单独的新进程 $pid = $process->start();//启动进程,并获取进程id $workers[$pid] = $process; } //创建进程执行函数 function doProcess(swoole_process $process){ $process->write("PID:$process->id"); //子进程写入信息 echo "写入信息到:$process->id $process->callback"; } //添加进程事件 向每个子进程添加需要执行的动作 foreach($workers as $process){ //添加 swoole_event_add($process->pipe,function ($pipe) use($process){ $data = $process->read();//能否读取数据 echo "接受到:$data\n"; }); }
php-swoole 进程事件
最新推荐文章于 2023-02-02 18:31:05 发布