hyperf-chat/config/autoload/server.php

62 lines
2.2 KiB
PHP
Raw Normal View History

2020-11-02 22:45:37 +08:00
<?php
declare(strict_types=1);
/**
* 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
*/
use Hyperf\Server\Server;
use Hyperf\Server\SwooleEvent;
return [
'mode' => SWOOLE_PROCESS,
'servers' => [
[
'name' => 'http',
'type' => Server::SERVER_HTTP,
'host' => '0.0.0.0',
2020-11-03 14:07:54 +08:00
'port' => 9503,
2020-11-02 22:45:37 +08:00
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
],
],
[
'name' => 'ws',
'type' => Server::SERVER_WEBSOCKET,
'host' => '0.0.0.0',
2020-11-03 14:07:54 +08:00
'port' => 9504,
2020-11-02 22:45:37 +08:00
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
2020-11-07 22:57:10 +08:00
// 自定义握手处理
2020-11-02 22:45:37 +08:00
SwooleEvent::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
SwooleEvent::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
SwooleEvent::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
],
],
],
'settings' => [
'enable_coroutine' => true,
2020-11-04 22:58:49 +08:00
'worker_num' => 1,
2020-11-02 22:45:37 +08:00
'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
'open_tcp_nodelay' => true,
'max_coroutine' => 100000,
'open_http2_protocol' => true,
'max_request' => 100000,
2020-11-03 17:12:57 +08:00
'socket_buffer_size' => 3 * 1024 * 1024,
'buffer_output_size' => 3 * 1024 * 1024,
2020-11-04 07:54:11 +08:00
'package_max_length'=> 10 * 1024 * 1024,
2020-11-02 22:45:37 +08:00
],
'callbacks' => [
2020-11-04 11:57:16 +08:00
//自定义启动前事件
2020-11-07 22:57:10 +08:00
SwooleEvent::ON_BEFORE_START => [App\Bootstrap\ServerStart::class, 'beforeStart'],
2020-11-02 22:45:37 +08:00
SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
SwooleEvent::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
],
];