两台服务器都有业务逻辑处理代码:Event.php,内容一样,但就是不能sendToALL向所有连向两台服务器的客户端,发送只能到各自的客户端
A服务器正常部署,B服务器不写start_register.php,bussinessWorker服务和Gateway的注册地址指向A服务器,也就是由A服务器监控两台服务器的服务,
B服务器代码如下:start_gateway.php<?php use WorkermanWorker;use WorkermanWebServer;use GatewayWorkerGateway;use GatewayWorkerBusinessWorker;use WorkermanAutoloader;
// gateway 进程,这里使用Text协议,可以用telnet测试$gateway = new Gateway(_gateway_PORT_);// gateway名称,status方便查看$gateway->name = 'YourAppGateway';// gateway进程数$gateway->count = 3;// 本机ip,分布式部署时使用内网ip$gateway->lanIp = '0.0.0.0';// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口 $gateway->startPort = _startPort_;// 服务注册地址,指向A服务器$gateway->registerAddress = _registerAddress_;
// 心跳间隔$gateway->pingInterval = 15;//10 设置为0代表不发送心跳检测$gateway->pingNotResponseLimit = 30;// 心跳数据$gateway->pingData = '{"action2":"ping"}';
/* // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调$gateway->onConnect = function($connection){
$connection->onWebSocketConnect = function($connection , $http_header)
{
};
}; */
// 如果不是在根目录启动,则运行runAll方法if(!defined('GLOBAL_START')) {
Worker::runAll();
}?>start_businessworker_chat.php<?php /**
This file is part of workerman.
*
Licensed under The MIT License
For full copyright and license information, please see the MIT-LICENSE.txt
Redistributions of files must retain the above copyright notice.
*
@author walkor<walkor@workerman.net>
@copyright walkor<walkor@workerman.net>
@link http://www.workerman.net/
@license http://www.opensource.org/lic... MIT License
*/use WorkermanWorker;use WorkermanWebServer;use GatewayWorkerGateway;use GatewayWorkerBusinessWorker;use WorkermanAutoloader;use GlobalDataClient;
// bussinessWorker 进程$worker = new BusinessWorker();// worker名称$worker->name = 'ChatBusinessWorker';// bussinessWorker进程数量//只能开启一个进程,不同进程间变量是不通的$worker->count = 10;
// 设置业务超时时间10秒,需要配合业务$worker->processTimeout = 10;
// 服务注册地址 指向A服务器$worker->registerAddress = _registerAddress_;$worker->onWorkerStart = function($worker){ //GlobalData服务器端与本项目是同一个,如果有多台聊天服务器要将它分离出去
global $globaldata;
$globaldata = new GlobalData\Client(_GlobalData_IP_.':'._GlobalData_PORT_);
};// 如果不是在根目录启动,则运行runAll方法if(!defined('GLOBAL_START')) {
Worker::runAll();
}?>
1 回答
翻过高山走不出你
TA贡献1875条经验 获得超3个赞
$gateway->lanIp
内网地址不能写全0.register通过这个去找gateway的
gate1
$gateway = new Gateway("Websocket://0.0.0.0:8282");
// gateway名称,status方便查看
$gateway->name = 'gate2';
// gateway进程数
$gateway->count = 4;
// 本机ip,分布式部署时使用内网ip
$gateway->lanIp = '192.168.1.28';
// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
$gateway->startPort = 2900;
// 服务注册地址
$gateway->registerAddress = '192.168.1.59:1238';
gate2
$gateway = new Gateway("Websocket://0.0.0.0:8283");
// gateway名称,status方便查看
// gateway名称,status方便查看
$gateway->name = 'gate1';
// gateway进程数
$gateway->count = 4;
// 本机ip,分布式部署时使用内网ip
$gateway->lanIp = '192.168.1.59';
// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
$gateway->startPort = 2910;
// 服务注册地址
$gateway->registerAddress = '192.168.1.59:1238';
- 1 回答
- 0 关注
- 626 浏览
添加回答
举报
0/150
提交
取消