运行多个gatewayWorker实例

可以运行多个GatewayWorker实例,步骤如下。

假设已有Applications/Chat,想增加Applications/Chat2

1、拷贝Applications/Chat到Applications/Chat2

2、更改Applications/Chat2/start_register.php中的端口,1236改为1237(或者改为其它未被占用端口)

3、更改Applications/Chat2/start_businessworker.php中的registerAddress为127.0.0.1:1237

4、更改Applications/Chat2/start_gateway.php中的属性,包括gateway端口、startPort、registerAddress和进程名如下

  1. // ===更改gateway进程端口,这里改为8282===
  2. $gateway = new Gateway("Websocket://0.0.0.0:8282");
  3. // ===更改名称,方便status时查看===
  4. $gateway->name = 'ChatGateway2';
  5. $gateway->count = 4;
  6. $gateway->lanIp = '127.0.0.1';
  7. // ===更改注册服务地址,端口由1236改为1237===
  8. $gateway->registerAddress = '127.0.0.1:1237';
  9. // ===更改内部通讯起始端口,这里改为4000===
  10. $gateway->startPort = 4000;
  11. $gateway->pingInterval = 10;
  12. $gateway->pingData = '{"type":"ping"}';

5、更改Applications/Chat2/start_web.php中的WebServer端口,

  1. // 这里改成55252
  2. $web = new WebServer("http://0.0.0.0:55252");
  3. $web->count = 2;
  4. $web->addRoot('www.your_domain.com', __DIR__.'/Web');

6、由于gateway端口更改了,所以前端js连接gateway的端口也要做相应的更改

打开 /Applications/Chat2/Web/index.php

  1. // 改成gateway端口8282
  2. ws = new WebSocket("ws://"+document.domain+":8282");