hyperf-chat/config/autoload/server.php

69 lines
2.4 KiB
PHP
Raw Normal View History

2020-11-02 22:45:37 +08:00
<?php
declare(strict_types=1);
2020-11-28 19:59:10 +08:00
2020-11-02 22:45:37 +08:00
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
2020-11-28 19:59:10 +08:00
2020-11-02 22:45:37 +08:00
use Hyperf\Server\Server;
2021-08-27 23:50:40 +08:00
use Hyperf\Server\Event;
2020-11-02 22:45:37 +08:00
return [
2021-04-22 16:58:44 +08:00
'mode' => SWOOLE_PROCESS,
'servers' => [
2020-11-02 22:45:37 +08:00
[
2021-04-22 16:58:44 +08:00
'name' => 'http',
'type' => Server::SERVER_HTTP,
'host' => '0.0.0.0',
'port' => 9503,
2020-11-02 22:45:37 +08:00
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
2021-08-27 23:50:40 +08:00
Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
2020-11-02 22:45:37 +08:00
],
],
[
2021-04-22 16:58:44 +08:00
'name' => 'ws',
'type' => Server::SERVER_WEBSOCKET,
'host' => '0.0.0.0',
'port' => 9504,
2020-11-02 22:45:37 +08:00
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
2020-11-07 22:57:10 +08:00
// 自定义握手处理
2021-08-27 23:50:40 +08:00
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'],
2020-11-02 22:45:37 +08:00
],
2021-04-22 16:58:44 +08:00
'settings' => [
// 设置心跳检测
'heartbeat_idle_time' => 70,
2020-11-09 17:41:22 +08:00
'heartbeat_check_interval' => 30,
]
2020-11-02 22:45:37 +08:00
],
],
2021-04-22 16:58:44 +08:00
'settings' => [
'enable_coroutine' => true,
2021-07-10 00:18:40 +08:00
'worker_num' => env('SWOOLE_CPU_NUM', swoole_cpu_num() * 2),
2021-04-22 16:58:44 +08:00
'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
'open_tcp_nodelay' => true,
'max_coroutine' => 100000,
2020-11-02 22:45:37 +08:00
'open_http2_protocol' => true,
2021-04-22 16:58:44 +08:00
'max_request' => 10000,
'socket_buffer_size' => 3 * 1024 * 1024,
'buffer_output_size' => 3 * 1024 * 1024,
'package_max_length' => 10 * 1024 * 1024,
2020-11-02 22:45:37 +08:00
],
'callbacks' => [
2021-04-22 16:58:44 +08:00
// 自定义启动前事件
2021-08-27 23:50:40 +08:00
Event::ON_BEFORE_START => [App\Bootstrap\ServerStart::class, 'beforeStart'],
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'],
2020-11-02 22:45:37 +08:00
],
];