webman里安装好了gatewayworker,怎么监听两个websock的端口?

wekyun

webman里安装好了gatewayworker,只有一个websock的端口监听,想再加一个websock的新的端口监听别的业务,怎么做?
截图

<?php

use Webman\GatewayWorker\Gateway;
use Webman\GatewayWorker\BusinessWorker;
use Webman\GatewayWorker\Register;

return [
    'gateway' => [
        'handler' => Gateway::class,
        'listen' => 'websocket://0.0.0.0:7272',
        'count' => cpu_count(),
        'reloadable' => false,
        'constructor' => ['config' => [
            'lanIp' => '127.0.0.1',
            'startPort' => 2300,
            'pingNotResponseLimit' => 1,//客户端是否必须发送心跳给服务端,1发送,0不发送
            'pingInterval' => 55,
//            'pingData' => '{"msg_type":"ping"}',//服务端发送给客户端的心跳,注释了就不发送了
            'registerAddress' => '127.0.0.1:1236',
            'onConnect' => function () {
            },
        ]]
    ],
    'worker' => [
        'handler' => BusinessWorker::class,
        'count' => cpu_count() * 2,
        'constructor' => ['config' => [
            'eventHandler' => plugin\webman\gateway\Events::class,
            'name' => 'ChatBusinessWorker',
            'registerAddress' => '127.0.0.1:1236',
        ]]
    ],
    'register' => [
        'handler' => Register::class,
        'listen' => 'text://127.0.0.1:1236',
        'count' => 1, // Must be 1
        'constructor' => []
    ],
];
439 1 0
1个回答

walkor 打赏
return [
    'gateway' => [
        'handler' => Gateway::class,
        'listen' => 'websocket://0.0.0.0:7272',
        'count' => cpu_count(),
        'reloadable' => false,
        'constructor' => ['config' => [
            'lanIp' => '127.0.0.1',
            'startPort' => 2300,
            'pingNotResponseLimit' => 1,//客户端是否必须发送心跳给服务端,1发送,0不发送
            'pingInterval' => 55,
//            'pingData' => '{"msg_type":"ping"}',//服务端发送给客户端的心跳,注释了就不发送了
            'registerAddress' => '127.0.0.1:1236',
            'onConnect' => function () {
            },
        ]]
    ],
    'worker' => [
        'handler' => BusinessWorker::class,
        'count' => cpu_count() * 2,
        'constructor' => ['config' => [
            'eventHandler' => plugin\webman\gateway\Events::class,
            'name' => 'ChatBusinessWorker',
            'registerAddress' => '127.0.0.1:1236',
        ]]
    ],
    'register' => [
        'handler' => Register::class,
        'listen' => 'text://127.0.0.1:1236',
        'count' => 1, // Must be 1
        'constructor' => []
    ],
    'gateway2' => [
        'handler' => Gateway::class,
        'listen' => 'websocket://0.0.0.0:7373',
        'count' => cpu_count(),
        'reloadable' => false,
        'constructor' => ['config' => [
            'lanIp' => '127.0.0.1',
            'startPort' => 3300,
            'pingNotResponseLimit' => 1,//客户端是否必须发送心跳给服务端,1发送,0不发送
            'pingInterval' => 55,
//            'pingData' => '{"msg_type":"ping"}',//服务端发送给客户端的心跳,注释了就不发送了
            'registerAddress' => '127.0.0.1:1236',
            'onConnect' => function () {
            },
        ]]
    ],
];
  • wekyun 2024-03-05

    7272和7373处理的业务如果要写在不同的Events.php文件中,要如何配置呀~

  • walkor 2024-03-05

    那就是属于部署两套分离的gatewayWorker,二者不互通。看gatewayWorker手册常见问题

  • wekyun 2024-03-05

    哦哦

  • wekyun 2024-03-05

    思路就是,按照在其他框架中使用GatewayWorker对吧

  • walkor 2024-03-05

    部署多实例

×
🔝