both servers have business logic processing code: Event.php, the content is the same, but cannot sendToALL to all clients connected to the two servers, which can only be sent to their respective clients
A server is deployed normally.
B server does not write the registered address of start_register.php,bussinessWorker service and Gateway to A server, that is, A server monitors the services of the two servers.
B server code is as follows:
start_gateway.php
php
use WorkermanWorker;
use WorkermanWebServer;
use GatewayWorkerGateway;
use GatewayWorkerBusinessWorker;
use WorkermanAutoloader;
/ / gateway process, which uses the Text protocol, and can be tested with telnet
$gateway = new Gateway (_ gateway_PORT_);
/ / gateway name. Status makes it easy to see
$gateway- > name = "YourAppGateway";
/ / gateway processes
$gateway- > count = 3;
/ / Native ip, use the intranet ip
$gateway- > lanIp =" 0.0.0.0" for distributed deployment
/ / Internal communication starting port. If $gateway- > count=4, the starting port is 4000
/ /, then 4000 4001 4002 4003 ports are generally used as the internal communication port
$gateway- > startPort = _ startPort_;
/ / Service Registration address, pointing to A server
$gateway- > registerAddress = _ registerAddress_;
/ / heartbeat interval
$gateway- > pingInterval = 15 pingData action2 10 set to 0 means no heartbeat detection is sent
$gateway- > pingNotResponseLimit = 30;
/ / heartbeat data
$gateway- > pingData ="{"action2": "ping"}";
/ *
/ / when the client connects, set the onWebSocketConnect of the connection, that is, the callback in the websocket handshake
$gateway- > onConnect = function ($connection)
{
$connection->onWebSocketConnect = function($connection , $http_header)
{
};
};
* /
/ / if it is not started in the root directory, run the runAll method
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 process
$worker = new BusinessWorker ();
/ / worker name
$worker- > name = "ChatBusinessWorker";
/ / number of bussinessWorker processes
/ / only one process can be started, and different inter-process variables are impassable
$worker- > count = 10;
/ / set the service timeout for 10 seconds, which needs to cooperate with the business
$worker- > processTimeout = 10;
/ / the service registration address points to A server
$worker- > registerAddress = _ registerAddress_;
$worker- > onWorkerStart = function ($worker)
{/ / GlobalData server is the same as this project, if there are multiple chat servers to separate it
global $globaldata;
$globaldata = new GlobalData\Client(_GlobalData_IP_.":"._GlobalData_PORT_);
};
/ / if it is not started in the root directory, run the runAll method
if (! defined ("GLOBAL_START")) {
Worker::runAll();
}
? >