* @copyright walkor * @link http://www.workerman.net/ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ use \Workerman\Worker; use \GatewayWorker\Gateway; // 自动加载类 require_once __DIR__ . '/../../vendor/autoload.php'; // gateway 进程 $fastchat_config = get_addon_config('fastchat'); $context = []; $ssl_start = false; if ($fastchat_config['wss_switch'] && $fastchat_config['ssl_cert_file'] && $fastchat_config['ssl_key_file']) { $context = array( // 更多ssl选项 http://php.net/manual/zh/context.ssl.php 'ssl' => array( // 使用绝对路径 'local_cert' => $fastchat_config['ssl_cert_file'], 'local_pk' => $fastchat_config['ssl_key_file'], 'verify_peer' => false, // 'allow_self_signed' => true, //如果是自签名证书开启此选项 ) ); $ssl_start = true; } $gateway = new Gateway("websocket://0.0.0.0:" . $fastchat_config['websocket_port'], $context); // 开始SSL if ($ssl_start) { $gateway->transport = 'ssl'; } // gateway名称,status方便查看 $gateway->name = 'FastChatGateway' . ($ssl_start ? '-wss' : ''); // gateway进程数 $gateway->count = $fastchat_config['gateway_process_number']; // 本机ip,分布式部署时使用内网ip $gateway->lanIp = '127.0.0.1'; // 内部通讯起始端口,假如$gateway->count=4,起始端口为4000 // 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口 $gateway->startPort = $fastchat_config['internal_start_port']; // 服务注册地址 $gateway->registerAddress = '127.0.0.1:' . $fastchat_config['register_port']; // 心跳间隔 $gateway->pingInterval = 30; $gateway->pingNotResponseLimit = 1; // 心跳数据 $gateway->pingData = ''; // 如果不是在根目录启动,则运行runAll方法 if (!defined('GLOBAL_START')) { Worker::runAll(); }