gateway-worker插件

v1.0.9 版本
2024-04-30 版本更新时间
19420 安装
14 star

简介

webman的gateway-worker插件,用于分布式即时通讯、物联网等领域。

安装

composer require webman/gateway-worker

使用

start_gateway.php start_businessworker.php start_register.php中相关的代码配置移动到
config/plugin/webman/gateway-worker/process.php

业务目录在 plugin/webman/gateway 目录

添加gateway进程参考配置

<?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,
            'pingInterval'    => 25,
            'pingData'        => '{"type":"ping"}',
            'registerAddress' => '127.0.0.1:1236',
            'onConnect'       => function(){},
        ]]
    ],
    'gateway-tcp' => [ // 假设增加一个tcp端口的gateway进程
        'handler'     => Gateway::class,
        'listen'      => 'tcp://0.0.0.0:7373', // 注意这里端口不能重复
        'count'       => cpu_count(),
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 3300, // 注意这里端口不能重复,步数大大一些,不能和上面2300太接近
            'pingInterval'    => 25,
            'pingData'        => '{"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://0.0.0.0:1236',
        'count'       => 1, // Must be 1
        'constructor' => []
    ],
];

更多参见gateway-worker手册

赞助商