- Process\Pool->on
- 子进程启动
- 子进程结束
- 消息接收
Process\Pool->on
设置进程池回调函数。
function Process\Pool::on(string $event, callable $function);
子进程启动
onWorkerStart回调函数,接受2个参数:
Pool对象WorkerId当前工作进程的编号,底层会对子进程进行标号,范围是[0-$worker_num)
function onWorkerStart(Swoole\Process\Pool $pool, int $workerId){echo "Worker#{$workerId} is started\n";}
子进程结束
onWorkerStop回调函数,与onWorkerStart参数一致。
消息接收
onMessage回调函数,收到外部投递的消息。一次连接只能投递一次消息, 类似于php-fpm的短连接机制.
Pool对象- 消息数据内容
function onMessage(Swoole\Process\Pool $pool, string $data){var_dump($data);}
