/** * 运行工作进程 */ function runWorker($worker_num = 1) { if (empty($this->config['logger'])) { $logger = new Log\EchoLog(array('display' => true)); } else { /** * Swoole\Log */ $logger = \Swoole::$php->log($this->config['logger']); } while (true) { $event = $this->_queue->pop(); if ($event) { $function = $event[0]; if (!is_callable($function)) { $logger->info('function [' . $function . '] not found.'); } else { $params = array_slice($event, 1); call_user_func_array($function, $params); } } else { usleep(100000); } } }
function _worker() { while ($this->_atomic->get() == 1) { $event = $this->_queue->pop(); if ($event) { $this->_execute($event['type'], $event['data']); } else { usleep(100000); } } }