case '-clear': if ($val == 'hashtable') { $clearhashtable = true; Logger::info('deleting hashtable'); } break; default: die('unknown option: ' + $opt . $usage); } //switch } //for } //if date_default_timezone_set(Options::getOption('timezone')); Timer::init(); /* * SEMAPHORE IDS * * */ define("OAIRECORDFILES", '4444'); define("STRINGIDFILE", '55555'); /* * A bunch of fixed strings * */ define("ACTIVE", 'active'); define("KEEP", 'keep'); define("PURGE", 'purge'); define("ARTICLE", 'article'); define("CATEGORY", 'category'); define("REDIRECT", 'redirect');
/** * 运行worker实例 */ public function run() { //更新 Worker 状态 self::$_status = self::STATUS_RUNNING; // 注册进程退出回调,用来检查是否有错误 register_shutdown_function(array("Worker", 'checkErrors')); // 设置自动加载根目录 Autoloader::setRootPath($this->_appInitPath); // 如果没有全局事件轮询,则创建一个 if (!self::$globalEvent) { if (extension_loaded('libevent')) { self::$globalEvent = new Libevent(); } else { self::$globalEvent = new Select(); } // 监听_mainSocket上的可读事件(客户端连接事件) if ($this->_socketName) { if ($this->transport !== 'udp') { self::$globalEvent->add($this->_mainSocket, EventInterface::EV_READ, array($this, 'acceptConnection')); } else { self::$globalEvent->add($this->_mainSocket, EventInterface::EV_READ, array($this, 'acceptUdpConnection')); } } } // 重新安装事件处理函数,使用全局事件轮询监听信号事件 self::reinstallSignal(); // 用全局事件轮询初始化定时器 Timer::init(self::$globalEvent); // 如果有设置进程启动回调,则执行 if ($this->onWorkerStart) { call_user_func($this->onWorkerStart, $this); } // 子进程主循环 self::$globalEvent->loop(); }