webman中使用GatewayWorker后registerAddress端口修改无效

黑老怪

创建一个新项目

composer create-project workerman/webman test
cd test
composer require webman/gateway-worker

创建完毕后修改 config/plugin/webman/gateway-worker/process.php

把默认的registerAddress修改为2236

return [
    'gateway' => [
        'handler'     => Gateway::class,
        'listen'      => 'websocket://0.0.0.0:7272',
        'count'       => 2,
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 2300,
            'pingInterval'    => 25,
            'pingData'        => '{"type":"ping"}',
            'registerAddress' => '127.0.0.1:2236',
            '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:2236',
        ]]
    ],
    'register' => [
        'handler'     => Register::class,
        'listen'      => 'text://127.0.0.1:2236',
        'count'       => 1, // Must be 1
        'reloadable'  => false,
        'constructor' => []
    ],
];

在plugin/webman/gateway/Events.php

    public static function onWorkerStart($worker)
    {
        var_dump(Gateway::$registerAddress);
    }

打印出来端口还是1236,并不是2236 但是我看程序还是正常.
截图

340 1 0
1个回答

walkor 打赏

配置里设置的是$businessWorker->registerAddress的值,不影响 Lib\Gateway::$registerAddress的值。
businessWorker进程里设置 Lib\Gateway::$registerAddress 没有意义,内部不会使用这个Lib\Gateway::$registerAddress的值

×
🔝