protected function settingCheck(&$setting) { //有一些配置是DIServer运行必须控制的。 if ($setting['task_worker_num'] <= 0) { throw new BootException("Error: 配置swoole.task_worker_num被设置为0。"); } if ($setting['task_ipc_mode'] != 2) { throw new BootException("Error: 配置swoole.task_ipc_mode设置不是2。"); } if ($setting['dispatch_mode'] == 1 || $setting['dispatch_mode'] == 3) { throw new BootException("Error: 配置swoole.dispatch_mode=1/3时,底层会屏蔽onConnect/onClose事件,原因是这2种模式下无法保证onConnect/onClose/onReceive的顺序。"); } if (isset($setting['chroot'])) { throw new BootException("Error: 配置swoole.chroot会导致autoloader无法在工作\\任务进程正常使用,请确定你能处理(如修改autoloader的路径)然后过来注释这个异常。"); } if (!isset($setting['package_eof'])) { $setting['package_eof'] = ''; //疑似swoole bug,如果不显式指定package_eof则无法正常收包。 } if (!isset($setting['task_tmpdir'])) { $setting['task_tmpdir'] = Application::GetServerPath('/Runtimes/TaskTemp'); } if (!isset($setting['log_file'])) { $setting['log_file'] = Application::GetServerPath('/Runtimes/Log/' . Application::GetServerName() . '.log'); } if (!isset($setting['message_queue_key'])) { $setting['message_queue_key'] = ftok(Application::GetServerPath(), 0); } $setting['daemonize'] = DI_DAEMONIZE; }
/** * 进程启动时被触发 * * @param \swoole_server $server 当前进程的swoole_server对象 * @param int $worker_id 当前进程的ID */ public function OnTaskWorkerStart(\swoole_server $server, $task_worker_id) { Log::Notice("On Task Worker[{$task_worker_id}] Start."); if (file_exists(Application::GetServerPath() . '/Registry/TaskWorker.php')) { $registry = (include Application::GetServerPath() . '/Registry/TaskWorker.php'); Application::AutoRegistry($registry); } Event::Listen('OnTaskWorkerStart', [&$server, &$task_worker_id]); }
/** * 重载Server/Handler */ private function _reloadServerHandler() { $path = Application::GetServerPath() . '/Registry/Handler.php'; if (file_exists($path)) { $handlerClasses = (include $path); //Log::Debug($handlerClasses); $this->_loadHandler($handlerClasses); } }
public function __construct() { $this->path = Application::GetServerPath('/Runtimes/Session'); // 锁定 $lockfile = $this->path . 'build.Runtimes.lock'; if (is_writable($lockfile)) { return; } else { if (!touch($lockfile)) { throw new \Exception('应用目录[' . $this->path . ']不可写,目录无法自动生成!请手动生成项目目录~', 10006); } } if (!is_dir($this->path)) { //echo "mkdir($this->path, 0755, true);\n"; mkdir($this->path, 0755, true); } // 解除锁定 unlink($lockfile); }
protected function setConfig() { //加载惯例配置//一次性配置,不用保存在内存中 $defaultConfig = (include Application::GetFrameworkPath() . '/Config/Swoole.php'); //加载自定义配置//一次性配置,不用保存在内存中 $serverConfig = (include Application::GetServerPath() . '/Config/Swoole.php'); //更新配置 foreach ($defaultConfig as $key => $value) { if (isset($serverConfig[$key])) { //如果存在Server的重定义,则重定义。 $defaultConfig[$key] = $serverConfig[$key]; } if (empty($defaultConfig[$key])) { //如果不存在,unset之 unset($defaultConfig[$key]); } } $this->settingCheck($defaultConfig); $this->swoole->set($defaultConfig); }