public static function init() { Daemon::$eventBase = event_base_new(); $args = $_SERVER['argv']; if (!isset($args[1]) || !isset($args[2])) { Terminal::drawStr('usage: php xxx.php sArea (start|stop|restart|reload|status)' . "\n"); exit(-1); } // todo run multi app in one daemon. $sArea = $args[1]; $command = $args[2]; $appName = Config::get('socket_server_class', null, true); Daemon::$runName = $appName; $runAppInstance = array($appName => $appName); if ($command == 'start') { // fork later self::$pid = posix_getpid(); Debug::log('start'); foreach ($runAppInstance as $appName) { $obj = new $appName(); } while (!Daemon::$breakEventLoop) { event_base_loop(daemon::$eventBase, EVLOOP_ONCE); // 清空本次写状态数组 gc_collect_cycles(); //daemon::debug('<== evet_base_loop() ending'); } } elseif ($command == 'stop') { // cat pid, stop } elseif ($command == 'status') { // cat pid, show status } elseif ($command == 'restart') { //self::stop(); //self::start(); } }