每个worker实例进程都有唯一的编号,即: $worker->id 属性,可以据此设置定时器,比如:
$worker->count = 4; $worker->onWorkerStart = function($worker) { //比如:只给id为0的进程设置定时器 if($worker->id === 0) { Timer::add(1, function(){ pprint("共启动了4个worker进程,只给0号进程设置定时器"); }); } };
onmessage里面的参数没看到有woker呢 怎么获取进程id呢
onMessage($connection, $data) 回调有$connection对象, 通过 $connection->woker 路由。
$connection->woker->id
每个worker实例进程都有唯一的编号,即: $worker->id 属性,可以据此设置定时器,比如:
onmessage里面的参数没看到有woker呢 怎么获取进程id呢
onMessage($connection, $data) 回调有$connection对象, 通过 $connection->woker 路由。
$connection->woker->id