Пример #1
0
 function run($setting = array())
 {
     $this->swooleSetting = array_merge($this->swooleSetting, $setting);
     if (!empty($this->swooleSetting['pid_file'])) {
         $this->pid_file = $this->swooleSetting['pid_file'];
     }
     $this->sw->set($this->swooleSetting);
     $version = explode('.', SWOOLE_VERSION);
     //1.7.0
     if ($version[1] >= 7) {
         $this->sw->on('ManagerStart', function ($serv) {
             global $argv;
             Swoole\Console::setProcessName('php ' . $argv[0] . ': manager');
         });
     }
     $this->sw->on('Start', array($this, 'onMasterStart'));
     $this->sw->on('ManagerStop', array($this, 'onManagerStop'));
     $this->sw->on('WorkerStart', array($this->protocol, 'onStart'));
     $this->sw->on('Connect', array($this->protocol, 'onConnect'));
     $this->sw->on('Receive', array($this->protocol, 'onReceive'));
     $this->sw->on('Close', array($this->protocol, 'onClose'));
     $this->sw->on('WorkerStop', array($this->protocol, 'onShutdown'));
     if (is_callable(array($this->protocol, 'onTimer'))) {
         $this->sw->on('Timer', array($this->protocol, 'onTimer'));
     }
     if (is_callable(array($this->protocol, 'onTask'))) {
         $this->sw->on('Task', array($this->protocol, 'onTask'));
         $this->sw->on('Finish', array($this->protocol, 'onFinish'));
     }
     $this->sw->start();
 }
Пример #2
0
 function onStart($serv, $worker_id = 0)
 {
     if (!defined('WEBROOT')) {
         define('WEBROOT', $this->config['server']['webroot']);
     }
     if (isset($this->config['server']['user'])) {
         Swoole\Console::changeUser($this->config['server']['user']);
     }
     Swoole\Error::$echo_html = true;
     $this->swoole_server = $serv;
     Swoole::$php->server = $this;
     $this->log(self::SOFTWARE . "[#{$worker_id}]. running. on {$this->server->host}:{$this->server->port}");
     register_shutdown_function(array($this, 'onError'));
 }
Пример #3
0
 function onStart($serv, $worker_id = 0)
 {
     global $yaf;
     if (!defined('WEBROOT')) {
         define('WEBROOT', $this->config['server']['webroot']);
     }
     if (isset($this->config['server']['user'])) {
         Swoole\Console::changeUser($this->config['server']['user']);
     }
     $this->application = new \Yaf_Application(WEBPATH . "/conf/application.ini");
     $yaf->application = $this->application;
     Swoole\Error::$echo_html = true;
     $this->swoole_server = $serv;
     //Swoole::$php->server = $this;
     $this->log(self::SOFTWARE . "[#{$worker_id}]. running. on {$this->server->host}:{$this->server->port}");
     set_error_handler(array($this, 'onErrorHandle'), E_USER_ERROR);
     register_shutdown_function(array($this, 'onErrorShutDown'));
 }
 function onStart($serv, $worker_id = 0)
 {
     if (!defined('WEBROOT')) {
         define('WEBROOT', $this->config['server']['webroot']);
     }
     if (isset($this->config['server']['user'])) {
         Swoole\Console::changeUser($this->config['server']['user']);
     }
     if ($this->server instanceof Swoole\Network\Server and isset($this->config['server']['process_rename'])) {
         global $argv;
         if ($worker_id >= $serv->setting['worker_num']) {
             Swoole\Console::setProcessName('php ' . $argv[0] . ': task');
         } else {
             Swoole\Console::setProcessName('php ' . $argv[0] . ': worker');
         }
     }
     Swoole\Error::$echo_html = true;
     $this->swoole_server = $serv;
     Swoole::$php->server = $this;
     $this->log(self::SOFTWARE . "[#{$worker_id}]. running. on {$this->server->host}:{$this->server->port}");
     register_shutdown_function(array($this, 'onError'));
 }
Пример #5
0
 function run($setting = array())
 {
     $this->runtimeSetting = array_merge($this->runtimeSetting, $setting);
     if (self::$pidFile) {
         $this->runtimeSetting['pid_file'] = self::$pidFile;
     }
     if (!empty(self::$options['daemon'])) {
         $this->runtimeSetting['daemonize'] = true;
     }
     if (!empty(self::$options['worker'])) {
         $this->runtimeSetting['worker_num'] = intval(self::$options['worker']);
     }
     if (!empty(self::$options['thread'])) {
         $this->runtimeSetting['reator_num'] = intval(self::$options['thread']);
     }
     if (!empty(self::$options['tasker'])) {
         $this->runtimeSetting['task_worker_num'] = intval(self::$options['tasker']);
     }
     $this->sw->set($this->runtimeSetting);
     $version = explode('.', SWOOLE_VERSION);
     //1.7.0
     if ($version[1] >= 7) {
         $this->sw->on('ManagerStart', function ($serv) {
             Swoole\Console::setProcessName($this->getProcessName() . ': manager');
         });
     }
     $this->sw->on('Start', array($this, 'onMasterStart'));
     $this->sw->on('Shutdown', array($this, 'onMasterStop'));
     $this->sw->on('ManagerStop', array($this, 'onManagerStop'));
     $this->sw->on('WorkerStart', array($this, 'onWorkerStart'));
     $this->sw->on('Connect', array($this->protocol, 'onConnect'));
     $this->sw->on('Receive', array($this->protocol, 'onReceive'));
     $this->sw->on('Close', array($this->protocol, 'onClose'));
     $this->sw->on('WorkerStop', array($this->protocol, 'onShutdown'));
     //swoole-1.8已经移除了onTimer回调函数
     if ($version[1] < 8) {
         if (is_callable(array($this->protocol, 'onTimer'))) {
             $this->sw->on('Timer', array($this->protocol, 'onTimer'));
         }
     }
     if (is_callable(array($this->protocol, 'onTask'))) {
         $this->sw->on('Task', array($this->protocol, 'onTask'));
         $this->sw->on('Finish', array($this->protocol, 'onFinish'));
     }
     $this->sw->start();
 }
Пример #6
0
 public function onWorkerStart($server, $workerId)
 {
     if ($workerId >= $this->setting['worker_num']) {
         Console::setProcessName($this->processName . ': task worker process');
     } else {
         Console::setProcessName($this->processName . ': event worker process');
     }
     if ($this->user) {
         Console::changeUser($this->user);
     }
     // check protocol class
     if (!$this->protocol) {
         throw new \Exception("[error] the protocol class  is empty or undefined");
     }
     $this->protocol->onStart($server, $workerId);
 }