swoole_server::$worker_id
�õ���ǰWorker���̵ı�ţ�����Task���̡�
int $server->worker_id;
���ӣ�������$worker_id,��$worker_id=0��ʱ�����һ����ʱ����
<?php $serv = new swoole_server("0.0.0.0", 9501); $serv->set(array( 'worker_num' => 2, 'dispatch_mode' => 3, 'daemonize' => false, 'log_file' => '/tmp/swoole.log' )); $serv->on('start', function($serv) { echo 'start',PHP_EOL; }); $serv->on('workerStart', function($serv, $worker_id) { if($worker_id == 0) { swoole_timer_tick(2000, function($id) { echo "tick-1 2000ms\n"; var_dump($id); }); } echo "server start\n"; }); $serv->on('connect', function ($serv, $fd, $from_id){ echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Connect.\n"; }); $serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) { echo "[#".$serv->worker_id."]\tClient[$fd]: $data\n"; $serv->send($fd, json_encode(array("hello" => '1213', "bat" => "ab")).PHP_EOL); $serv->close($fd); }); $serv->on('close', function ($serv, $fd, $from_id) { echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Close.\n"; }); $serv->start();
���������onWorkerStartʱ��$worker_id����ͬ�ġ�
- Worker����ID����[0, $serv->setting['worker_num'])
- task����ID����[$serv->setting['worker_num'], $serv->setting['worker_num'] + $serv->setting['task_worker_num'])
�������������worker_id��ֵ�Dz����