作为程序员一定要保持良好的睡眠,才能好编程

设置swoole启动进程的名称

发布时间:2019-03-26



php代码:

//设置进程名称,一般放在 Start中
public function onStart($serv){ 
   
        swoole_set_process_name("php5 master {$serv->master_pid}");    
    }    

    
    
 public function onWorkerStart($serv, $worker_id)    
    {    
        if ($worker_id >= $serv->setting['worker_num']) {    
            swoole_set_process_name("php5 task {$worker_id}");    
        } else {    
            swoole_set_process_name("php5 worker {$worker_id}");    
            $server = $this;    
            
            
            swoole_timer_tick(500, function() use ($server){    
                if (!empty($server->_wait_queue)) {    
                    $data = array_shift($server->_wait_queue);    
                    $task_id = $server->_getFreeTaskId($data['fd']);    
                    if ($task_id == -1) {    
                        $server->_wait_queue[] = $data;    
                    } else {    
                        $server->_serv->task(json_encode($data), $task_id);    
                    }    
                }    
//                echo "nothing doing...";    
            });    
            
            
        }    
    }