예제 #1
0
 /**
  * 初始化
  */
 private function __construct($ip, $port)
 {
     register_shutdown_function(array($this, 'handleFatal'));
     $http = new \swoole_http_server($ip, $port);
     $http->set(\Config\Server::getWebServerConfig());
     $http->on('WorkerStart', array($this, 'onWorkerStart'));
     $http->on('request', array($this, 'onRequest'));
     $http->on('start', array($this, 'onStart'));
     $http->start();
 }
예제 #2
0
파일: Worker.php 프로젝트: hioop/statistics
 public function run($ip = "0.0.0.0", $port = 55656, $mode = SWOOLE_PROCESS, $type = SWOOLE_SOCK_UDP)
 {
     if (empty($port)) {
         $port = $this->handleWorkerPort;
     } else {
         $this->handleWorkerPort = $port;
     }
     $serv = new \swoole_server($ip, $port, $mode, $type);
     //处理客户端发送的数据
     $serv->addlistener('0.0.0.0', $this->handleProviderPort, SWOOLE_SOCK_TCP | SWOOLE_SOCK_UDP);
     //处理统计页面请求的数据
     $serv->addlistener('0.0.0.0', $this->udpFinderport, SWOOLE_SOCK_UDP);
     //recv udp broadcast
     $serv->config = \Config\Server::getServerConfig();
     $serv->set($serv->config);
     $serv->on('Start', array($this, 'onStart'));
     $serv->on('WorkerStart', array($this, 'onWorkerStart'));
     $serv->on('Connect', array($this, 'onConnect'));
     $serv->on('Receive', array($this, 'onReceive'));
     $serv->on('Task', array($this, 'onTask'));
     $serv->on('Finish', array($this, 'onFinish'));
     $serv->on('WorkerError', array($this, 'onWorkerError'));
     $serv->on('Close', array($this, 'onClose'));
     $serv->on('WorkerStop', array($this, 'onWorkerStop'));
     $serv->on('Shutdown', array($this, 'onShutdown'));
     $serv->on('ManagerStart', function ($serv) {
         global $argv;
         swoole_set_process_name("php {$argv[0]}: manager");
     });
     $serv->start();
 }
예제 #3
0
 public function run($ip = "0.0.0.0", $port = 6666)
 {
     $webServer = new \swoole_http_server($ip, $port);
     $webServer->set(\Config\Server::getWebServerConfig());
     $webServer->on('WorkerStart', array($this, 'onWorkerStart'));
     $webServer->on('request', array($this, 'onRequest'));
     $webServer->on('start', array($this, 'onStart'));
     $webServer->on('ManagerStart', function ($serv) {
         global $argv;
         swoole_set_process_name("php {$argv[0]}: manager");
     });
     $webServer->start();
 }