企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Process\Pool->on 设置进程池回调函数。 ```php function Process\Pool::on(string $event, callable $function); ``` 子进程启动 ---- `onWorkerStart`回调函数,接受`2`个参数: 1. `Pool`对象 2. `WorkerId`当前工作进程的编号,底层会对子进程进行标号,范围是`[0-$worker_num)` ```php function onWorkerStart(Swoole\Process\Pool $pool, int $workerId) { echo "Worker#{$workerId} is started\n"; } ``` 子进程结束 ---- `onWorkerStop`回调函数,与`onWorkerStart`参数一致。 消息接收 ---- `onMessage`回调函数,收到外部投递的消息。 一次连接只能投递一次消息, 类似于php-fpm的短连接机制. 1. `Pool`对象 2. 消息数据内容 ```php function onMessage(Swoole\Process\Pool $pool, string $data) { var_dump($data); } ```