/** * 构造函数 * @throws \Exception */ private function __construct() { // 主配置位置 $config_file = WORKERMAN_ROOT_DIR . '/conf/workerman.conf'; if (!file_exists($config_file)) { throw new \Exception('Configuration file "' . $config_file . '" not found'); } // 载入主配置 self::$config['workerman'] = self::parseFile($config_file); self::$config['workerman']['log_dir'] = isset(self::$config['workerman']['log_dir']) ? self::$config['workerman']['log_dir'] : WORKERMAN_ROOT_DIR . '/logs'; self::$configFile = realpath($config_file); // 寻找应用配置 $conf_d = isset(self::$config['workerman']['include']) ? self::$config['workerman']['include'] : self::DEFAULT_CONFD_PATH; $index = 1; foreach (glob($conf_d) as $config_file) { $worker_name = basename($config_file, '.conf'); $config_data = self::parseFile($config_file); if (isset(self::$config[$worker_name])) { $worker_name = $worker_name . '-' . $index++; } if (!isset($config_data['enable']) || $config_data['enable']) { self::$config[$worker_name] = self::parseFile($config_file); } else { continue; } // 支持 WORKERMAN_ROOT_DIR 配置 array_walk_recursive(self::$config[$worker_name], array('\\Man\\Core\\Lib\\Config', 'replaceWORKERMAN_ROOT_DIR')); // 找出绝对路径 $config_file = realpath($config_file); if (self::$config[$worker_name]['worker_file'][0] !== '/') { self::$config[$worker_name]['worker_file'] = dirname($config_file) . '/' . self::$config[$worker_name]['worker_file']; } if (!isset(self::$config[$worker_name]['chdir'])) { self::$config[$worker_name]['chdir'] = dirname($config_file); } } // 整理Monitor配置 self::$config['Monitor'] = self::$config['workerman']['Monitor']; unset(self::$config['workerman']['Monitor']); self::$config['Monitor']['worker_file'] = '../Common/Monitor.php'; self::$config['Monitor']['persistent_connection'] = 1; self::$config['Monitor']['start_workers'] = 1; self::$config['Monitor']['user'] = '******'; self::$config['Monitor']['preread_length'] = 8192; self::$config['Monitor']['exclude_path'] = isset(self::$config['Monitor']['exclude_path']) ? array_merge(self::$config['Monitor']['exclude_path'], get_included_files()) : get_included_files(); self::$config['Monitor']['exclude_path'][] = self::$config['workerman']['log_dir']; self::$config['Monitor']['exclude_path'][] = sys_get_temp_dir(); if (!isset(self::$config['Monitor']['listen'])) { $socket_file = '/tmp/workerman.' . fileinode(__FILE__) . '.sock'; self::$config['Monitor']['listen'] = 'unix://' . $socket_file; } // 支持 WORKERMAN_ROOT_DIR 配置 array_walk_recursive(self::$config['Monitor'], array('\\Man\\Core\\Lib\\Config', 'replaceWORKERMAN_ROOT_DIR')); }
/** * 构造函数 * @throws \Exception */ private function __construct() { $config_file = WORKERMAN_ROOT_DIR . '/conf/workerman.conf'; if (!file_exists($config_file)) { throw new \Exception('Configuration file "' . $config_file . '" not found'); } self::$config['workerman'] = self::parseFile($config_file); self::$configFile = realpath($config_file); foreach (glob(WORKERMAN_ROOT_DIR . 'conf/conf.d/*.conf') as $config_file) { $worker_name = basename($config_file, '.conf'); self::$config[$worker_name] = self::parseFile($config_file); } }