param('service'); $serviceName = ucfirst($serviceName); $daemonize = intval(Factory::request()->param('daemonize')); $serviceConfigPath = __DIR__ . DIRECTORY_SEPARATOR . $serviceName . DIRECTORY_SEPARATOR . 'Config'.DIRECTORY_SEPARATOR.'Config.php'; if (!file_exists($serviceConfigPath)) { exit($serviceConfigPath . 'config file is not found'); } Config::load($serviceConfigPath); $service = Config::getInstance()->get('service'); $buildSwooleConfig = [ 'worker_num' => 2, // 建议开启核数的1-4倍 'daemonize' => $daemonize, 'open_length_check' => true, // 开启协议解析 'package_length_type' => 'N', // 长度字段的类型 'package_length_offset' => 0, //第几个字节是包长度的值 'package_body_offset' => PACKAGE_BODY_OFFSET, //第几个字节开始计算包内容 'package_max_length' => PACKAGE_MAXLENG, //协议最大长度 ]; if($service['ssl'] == true){ $ssl = Config::getInstance()->get('ssl'); $buildSwooleConfig = array_merge($buildSwooleConfig, $ssl); } if ($daemonize) { $dir = sys_get_temp_dir(); $buildSwooleConfig['log_file'] = $dir . DIRECTORY_SEPARATOR . 'swoole_' . $serviceName . '.log'; echo '控制台信息输出请查看:' . $buildSwooleConfig['log_file'] . "\n"; } Factory::swoole($service, $service['type'])->setConfig($buildSwooleConfig)->begin();