现有两台服务器,192.168.0.1 / 192.168.0.2
按照文档 https://www.workerman.net/doc/gateway-worker/gateway-worker-separation.html部署
192.168.0.1:
start_regiester.php:
use \Workerman\Worker;
use \GatewayWorker\Register;
// register 服务必须是text协议
$register = new Register('text://192.168.0.1:1236');
// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
start_getway.php:
use \Workerman\Worker;
use \GatewayWorker\Gateway;
use \Workerman\Autoloader;
// gateway 进程
$gateway = new Gateway("Websocket://0.0.0.0:7272");
// 设置名称,方便status时查看
$gateway->name = 'ChatGateway';
// 设置进程数,gateway进程数建议与cpu核数相同
$gateway->count = 8;
// 分布式部署时请设置成内网ip(非127.0.0.1)
$gateway->lanIp = '192.168.0.1';
$gateway->startPort = 2300;
$gateway->reusePort = true;
// 心跳间隔
$gateway->pingInterval = 30;
$gateway->pingNotResponseLimit = 0;
// 心跳数据
$gateway->pingData = '{"msgtype":"ping"}';
// 服务注册地址
$gateway->registerAddress = ["192.168.0.1:1236","192.168.0.2:1236"];
// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
start_businessworker.php:
use \Workerman\Worker;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
// bussinessWorker 进程
$worker = new BusinessWorker();
// worker名称
$worker->name = 'ChatBusinessWorker';
// bussinessWorker进程数量
$worker->count = 32;
// 服务注册地址
$worker->registerAddress = ["192.168.0.1:1236","192.168.0.2:1236"];
// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
php start.php start 出现错误:
PHP Warning: strpos() expects parameter 1 to be string, array given in /www/wwwroot/workerman-singing/vendor/workerman/gateway-worker/src/Gateway.php on line 472
版本信息:
Workerman version:3.4.2 PHP version:7.1.33
start time:2024-01-23 10:23:57 run 0 days 3 hours
load average: 1.47, 1, 1 event-loop:\Workerman\Events\Event
一看不就是start_businessworker.php第26行的错误么
start_businessworker.php:
use \Workerman\Worker;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
// bussinessWorker 进程
$worker = new BusinessWorker();
// worker名称
$worker->name = 'ChatBusinessWorker';
// bussinessWorker进程数量
$worker->count = 32;
// 服务注册地址
$worker->registerAddress = ["192.168.0.1:1236","192.168.0.2:1236"];
// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}内容没看出哪里不对
你的GatewayWorker版本太老了,弄了个6年前的版本
没办法,老项目了。
那你自己看代码解决吧,至少你这个版本的registerAddress看着是不支持多个的,
就是Register只有一个,但是GatewayWorker和BusinessWorker可以分开部署,原理一样,上面的代码改改就行
分开部署正常了。不支持数组模式