start_gateway.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * This file is part of workerman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. use \Workerman\Worker;
  15. use \GatewayWorker\Gateway;
  16. // 自动加载类
  17. require_once __DIR__ . '/../../vendor/autoload.php';
  18. if (Config['gateway']['is_run']) {
  19. // gateway 进程,这里使用Text协议,可以用telnet测试
  20. $gateway = new Gateway("tcp://0.0.0.0:" . Config['gateway']['port']);
  21. // gateway名称,status方便查看
  22. $gateway->name = Config['name'] . 'Gateway';
  23. // gateway进程数
  24. $gateway->count = Config['gateway']['count'];
  25. // 本机ip,分布式部署时使用内网ip
  26. $gateway->lanIp = Config['gateway_lanIp'];
  27. // 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
  28. // 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
  29. $gateway->startPort = Config['gateway']['startPort'];
  30. // 服务注册地址
  31. $gateway->registerAddress = Config['registerAddress'];
  32. // 心跳间隔
  33. $gateway->pingInterval = Config['gateway']['pingInterval'];
  34. $gateway->pingNotResponseLimit = Config['gateway']['pingNotResponseLimit'];
  35. // 心跳数据
  36. $gateway->pingData = '';
  37. // 如果不是在根目录启动,则运行runAll方法
  38. if (!defined('GLOBAL_START')) {
  39. Worker::runAll();
  40. }
  41. }