コード例 #1
0
ファイル: tcp.php プロジェクト: xiaoyjy/retry
 function request()
 {
     if (feof($this->client)) {
         $this->active_num--;
         return $this->next_loop();
     }
     $this->request_init();
     try {
         $dt = call_user_func($this->callback, $this->client);
     } catch (Exception $e) {
         $this->active_num--;
         cy_log(CYE_ERROR, "srv-request " . $e->getMessage());
         return $this->next_loop();
     }
     /* 当errno 为 CYE_DATA_EMPTY时为无效调用,一般为客户端主动断开连接,忽略 */
     if ($dt['errno'] == CYE_DATA_EMPTY) {
         $this->active_num--;
         return $this->next_loop();
     }
     cy_i_inc($this->rnum_name, CY_TYPE_SYS, 1);
     $this->request_shutdown();
     /* 为防止memory leak, 每个进程在处理一定量的请求之后就退出。 */
     if (++$this->requests > $this->max_requests) {
         $this->srv_shutdown();
         cy_log(CYE_WARNING, "process " . $this->pid . " exit after " . $this->max_requests . " requests");
     }
     /* 所有处理按长连接进行 */
     $this->last_request_time = microtime(true);
     $this->active_num--;
     // $this->lp->invokePending();
     return $this->next_loop();
 }
コード例 #2
0
ファイル: main.php プロジェクト: xiaoyjy/retry
 function worker_fork($key)
 {
     switch ($pid = pcntl_fork()) {
         case -1:
             cy_log(CYE_ERROR, "pcntl_fork({$key}) error.");
             break;
         case 0:
             $this->worker_init();
             // child process loop here.
             $this->servers['worker']->loop();
             // child process exit normal.
             exit(0);
         default:
             cy_i_inc('bps_srv_' . $key . '_num', CY_TYPE_SYS, 1);
             $w = [];
             $w['pw'] = $this->loop->child($pid, false, [$this, 'worker_onexit']);
             $w['key'] = $key;
             $w['flag'] = $this->flag;
             $this->workers[$pid] = $w;
             break;
     }
 }