SWOOLE_PROCESS, 'servers' => [ [ 'name' => 'http', 'type' => Server::SERVER_HTTP, 'host' => '0.0.0.0', 'port' => 9501, 'sock_type' => SWOOLE_SOCK_TCP, 'callbacks' => [ Event::ON_REQUEST => [App\Service\Server\StreamServer::class, 'onRequest'], // Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'], ], ], [ 'name' => 'ws', 'type' => Server::SERVER_WEBSOCKET, 'host' => '0.0.0.0', 'port' => 9506, 'sock_type' => SWOOLE_SOCK_TCP, 'callbacks' => [ Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'], Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'], Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'], ], 'settings' => [ // 关键:设置连接最大闲置时间(秒),0 表示永不超时 'max_idle_time' => 300, // 例如设置为 5 分钟 // 其他可能相关的配置 'open_tcp_keepalive' => 1, // 开启 TCP 保活机制 'tcp_keepidle' => 60, // 60 秒内无数据则发送保活探针 'tcp_keepinterval' => 10, // 探针间隔 10 秒 'tcp_keepcount' => 3, // 探针失败 3 次后关闭连接 ], ], ], 'settings' => [ 'document_root' => BASE_PATH . '/public', 'enable_static_handler' => true, Constant::OPTION_ENABLE_COROUTINE => true, Constant::OPTION_WORKER_NUM => swoole_cpu_num(), Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid', Constant::OPTION_OPEN_TCP_NODELAY => true, Constant::OPTION_MAX_COROUTINE => 10 * 1024 * 1024, Constant::OPTION_OPEN_HTTP2_PROTOCOL => true, Constant::OPTION_MAX_REQUEST => 10 * 1024 * 1024, Constant::OPTION_SOCKET_BUFFER_SIZE => 10 * 1024 * 1024, Constant::OPTION_BUFFER_OUTPUT_SIZE => 10 * 1024 * 1024, Constant::OPTION_UPLOAD_MAX_FILESIZE => 10 * 1024 * 1024, ], 'callbacks' => [ Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], ], ];