Ejemplo n.º 1
0
 public function __construct()
 {
     $this->process = new swoole_process(array($this, 'run'), false, true);
     if (!$this->process->useQueue(123)) {
         var_dump(swoole_strerror(swoole_errno()));
         exit;
     }
     $this->process->start();
     while (true) {
         $data = $this->process->pop();
         echo "RECV: " . $data . PHP_EOL;
     }
 }
Ejemplo n.º 2
0
 private function spawnCustomWorker($worker_name, $config)
 {
     $process = new \swoole_process(function (\swoole_process $worker) {
         $recv = $worker->pop();
         $worker_config = unserialize($recv);
         extract($worker_config);
         $name = isset($this->serverConfig['server']['worker_process_name']) ? $this->serverConfig['server']['worker_process_name'] : 'ypf:swoole-worker-%d';
         $processName = sprintf("{$name}:%s", 0, $worker_name);
         \swoole_set_process_name($processName);
         self::getInstance()->disPatch($config['action'], array('worker_name' => $worker_name));
     }, false, false);
     $process->useQueue();
     $pid = $process->start();
     $this->worker_pid[] = $pid;
     $process->push(serialize(array('pid' => $pid, 'worker_name' => $worker_name, 'config' => $config)));
     if ($pid > 0) {
         echo "starting worker : {$worker_name}        [ OK ]\n";
     } else {
         echo "starting worker : {$worker_name}        [ FAIL ]  '" . \swoole_strerror(swoole_errno()) . "' \n";
     }
 }
Ejemplo n.º 3
0
 public function start()
 {
     // 只能单例运行
     if ($this->config['is_sington'] == true) {
         $this->checkPidfile();
     }
     $this->createPidfile();
     if (!isset($this->on_func['request'])) {
         log::prn_log(ERROR, "must set on_request callback function!");
         exit;
     }
     $this->serv->start();
     if (!$this->shutdown) {
         log::prn_log(ERROR, "swoole start error: " . swoole_errno() . ',' . swoole_strerror(swoole_errno()));
     }
 }
Ejemplo n.º 4
0
Archivo: swoole.php Proyecto: loder/asf
 public function start()
 {
     // 只能单例运行
     if ($this->config['is_sington'] == true) {
         $this->checkPidfile();
     }
     $this->createPidfile();
     $this->serv->start();
     if (!$this->shutdown) {
         log::prn_log(ERROR, "swoole start error: " . swoole_errno() . ',' . swoole_strerror(swoole_errno()));
     }
 }