/** * LibEvLoop constructor. */ public function __construct() { $this->loop = \EvLoop::defaultLoop(); $this->nextTickQueue = new NextTickQueue($this); $this->futureTickQueue = new FutureTickQueue($this); $this->timerEvents = new SplObjectStorage(); }
function start() { //$this->deamonlize(); cy_i_drop(CY_TYPE_SYS); cy_i_init(CY_TYPE_SYS); cy_i_set('bps_srv_status', CY_TYPE_SYS, 0); $pid = posix_getpid(); $param = []; $name = ''; foreach ($_ENV['server'] as $type => $arr) { if (empty($pid)) { break; } if (empty($arr['enable'])) { continue; } $name = $type; $param = $arr; switch ($pid = pcntl_fork()) { case -1: cy_log(CYE_ERROR, "pcntl_fork({$key}) error."); exit(-1); case 0: $this->type = $type; break; default: break; } } if ($pid || empty($name) || empty($param)) { exit(0); } $ptname = "CY_Srv_Protocol_" . $name; if (!class_exists($ptname)) { exit("unkown server implements " . $ptname . "\n"); } $wkname = 'CY_Srv_' . $param['worker']; if (!class_exists($wkname)) { exit("unkown server implements " . $wkname . "\n"); } $worker = new $wkname($param['listen'], [new $ptname(), 'run'], $name); $this->servers = ['stat' => ['number' => 0, 'status' => 0], 'list' => [], 'worker' => $worker]; cy_i_set('bps_srv_' . $name . '_num', CY_TYPE_SYS, 0); cy_i_set('bps_srv_' . $name . '_req_num', CY_TYPE_SYS, 0); $this->flag = WKST_RUNNING; $this->loop = EvLoop::defaultLoop(); $this->worker_start(); // master process is here. //cy_title($this->cmd." [master]"); // check dead lock. check every 10 second. $this->watcher['ta'] = $this->loop->timer(0, 2, [$this, 'master_timer']); // master loop here. $this->loop->run(); }
/** * Initialise the current process state and watchers. */ public function init() { // Define current process environment. $this->pid = posix_getpid(); $this->loop = \EvLoop::defaultLoop(); }