$worker = new Worker('tcp://0.0.0.0:9090');
//启动1个进程对外提供服务
$worker -> count = 1;
Worker::$daemonize = true;
Worker::$stdoutFile = '/tmp/stdout.log';
//增加一个属性
$worker -> uidConnections = array();//c++客户端信息
$worker -> onWorkerStart = function($worker){$alarm = new Alarm();//这是新开了另一个worker
$alarm -> start();$allLine = new AllLine();//这是新开了另一个worker
$allLine -> start();
$worker -> onConnect = function($connection){
global $worker;
$ip = $connection -> getRemoteIp();
$id = $connection -> id;
$worker -> uidConnections = $connection;
$GLOBALS = Timer::add(0.001,array('DealData','dealSream'),array($id, $connection),true);//隔1ms处理一次stream
};
$worker -> onMessage = function($connection,$datas){
//#考虑校验
$GLOBALS += strlen($datas);
$id = $connection -> id;
if(!isset($GLOBALS)){
$GLOBALS = $datas;
}else{
$GLOBALS .= $datas;//接收流到缓冲区
}
};如上,新开的两个worker如果业务比较慢,会否影响最外层worker的接收数据?里面两个算是子进程吗
1. 位于onWorkerStart内worker如果业务比较慢,会影响到即阻塞最外层worker的接收数据的。
2. 位于onWorkerStart内worker所在的进程是子进程。
3. 如果业务比较繁重,就不要放在 onWorkerStart 里搞,应该采用异步模型将繁重的任务转发给独立的业务worker来搞。
ok。万分感谢。
请问怎么在worker内部再创建worker,我用Worker::runAll();会报错