Exemplo n.º 1
0
 function __construct($addr, $callback, $type)
 {
     //$this->lock_name = 'bps_'.$type.'_lock';
     $this->rnum_name = 'bps_srv_' . $type . '_req_num';
     $this->type = $type;
     $this->lp = new EvLoop(Ev::recommendedBackends());
     //cy_create_lock($this->lock_name);
     $this->srv = stream_socket_server($addr, $errno, $error, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
     if (!$this->srv) {
         // TODO notify father to stop process.
         cy_log(CYE_ERROR, $addr . ' bind failed, errno ' . $errno . ' error ' . $error);
         exit;
     }
     if (!is_callable($callback)) {
         cy_log(CYE_ERROR, 'invalid callback function');
         exit;
     }
     // set block mode
     stream_set_blocking($this->srv, 1);
     stream_set_timeout($this->srv, 0, 0.8);
     $this->callback = $callback;
 }
Exemplo n.º 2
0
Arquivo: hb.php Projeto: xiaoyjy/retry
 function __construct($addr, $callback, $type)
 {
     $this->type = $type;
     $this->addr = $addr;
     $this->lp = new EvLoop(Ev::recommendedBackends());
     $this->callback = $callback;
     if (!is_callable($callback)) {
         cy_log(CYE_ERROR, 'invalid callback function');
         exit;
     }
     $this->srv = stream_socket_server($this->addr, $errno, $error, STREAM_SERVER_BIND);
     if (!$this->srv) {
         // TODO notify father to stop process.
         cy_log(CYE_ERROR, $this->addr . ' bind failed, errno ' . $errno . ' error ' . $error);
         exit;
     }
     /* libev只支持水平触发,而水平触发的多进程模型是会惊群的,但阻塞句柄不会惊群 */
     stream_set_blocking($this->srv, 0);
     stream_set_timeout($this->srv, 0, 0.1);
     $this->aw = $this->lp->io($this->srv, Ev::READ, array($this, 'process'));
     $this->tw = $this->lp->timer(0, 1, array($this, 'timer'));
 }