zhoudw
2021-12-21 5391f51a59d9eda21914e5a71e5f7bc08bafd312
test
2 files modified
30 ■■■■ changed files
config/config.php 4 ●●●● patch | view | raw | blame | history
ws_server.php 26 ●●●● patch | view | raw | blame | history
config/config.php
@@ -2,7 +2,7 @@
/*
 * @Author: your name
 * @Date: 2021-12-15 11:33:00
 * @LastEditTime: 2021-12-21 14:23:49
 * @LastEditTime: 2021-12-21 17:53:53
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /websocket/config/config.php
@@ -15,7 +15,7 @@
    ),
    //本机WebSocket服务配置
    'server_config' => array(
        'allow_ip' => '120.25.156.26:58004',
        'allow_ip' => '120.25.156.26.58004',
        'host' => '0.0.0.0',
        'port' => '9501',
    ),
ws_server.php
@@ -21,20 +21,20 @@
        $this->redis_config  = $config['redis'];
        $this->server = new Swoole\WebSocket\Server($this->server_config['host'], $this->server_config['port']); // swoole连接
        $this->server->set(array(
            'worker_num' => 8,      //worker process num,设置启动的worker进程数量,测试时使用1个即可
            'backlog' => 128,       //listen backlog
            'max_conn' => 100000,      // Server最大允许维持多少个tcp连接。超过此数量后,新进入的连接将被拒绝
            'max_request' => 0,     // worker进程在处理完n次请求后结束运行,manager会重新创建一个worker进程。设置为0表示不自动重启。若在Worker进程中需要保存连接信息的服务,需要设置为0
            // dispatch_mode 配置在BASE模式是无效的,因为BASE不存在投递任务
            // 进程数据包分配模式: 1平均分配,2按FD取摸固定分配,3抢占式分配,默认为取摸(dispatch=2),4按IP分配,5按UID分配(需要用户代码中调用$serv->bind_uid(将一个连接绑定1个uid)
            'dispatch_mode'=> 2,
            'daemonize' => true,   // 若设置为true,执行php server.php将转入后台作为守护进程运行
            'log_file' => 'swoole-test_ws.log', // daemonize为true时,输出内容才会写入到该日志文件
        // $this->server->set(array(
        //     'worker_num' => 8,      //worker process num,设置启动的worker进程数量,测试时使用1个即可
        //     'backlog' => 128,       //listen backlog
        //     'max_conn' => 100000,      // Server最大允许维持多少个tcp连接。超过此数量后,新进入的连接将被拒绝
        //     'max_request' => 0,     // worker进程在处理完n次请求后结束运行,manager会重新创建一个worker进程。设置为0表示不自动重启。若在Worker进程中需要保存连接信息的服务,需要设置为0
        //     // dispatch_mode 配置在BASE模式是无效的,因为BASE不存在投递任务
        //     // 进程数据包分配模式: 1平均分配,2按FD取摸固定分配,3抢占式分配,默认为取摸(dispatch=2),4按IP分配,5按UID分配(需要用户代码中调用$serv->bind_uid(将一个连接绑定1个uid)
        //     'dispatch_mode'=> 2,
        //     'daemonize' => true,   // 若设置为true,执行php server.php将转入后台作为守护进程运行
            //'log_file' => 'swoole-test_ws.log', // daemonize为true时,输出内容才会写入到该日志文件
            //'heartbeat_idle_time' => 2000,        // 连接最大允许空闲的时间(秒),与heartbeat_check_interval配合使用.当dispatch_mode=1/3时,底层会屏蔽onConnect/onClose事件
            //'heartbeat_check_interval' => 2,   // 表示每隔多久轮循一次,单位为秒
        ));
        //     //'log_file' => 'swoole-test_ws.log', // daemonize为true时,输出内容才会写入到该日志文件
        //     //'heartbeat_idle_time' => 2000,        // 连接最大允许空闲的时间(秒),与heartbeat_check_interval配合使用.当dispatch_mode=1/3时,底层会屏蔽onConnect/onClose事件
        //     //'heartbeat_check_interval' => 2,   // 表示每隔多久轮循一次,单位为秒
        // ));
        /*
        $this->server->set([
            // 'task_worker_num'       => 8,