start_gateway.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // gateway 进程
  19. $fastchat_config = get_addon_config('fastchat');
  20. $context = [];
  21. $ssl_start = false;
  22. if ($fastchat_config['wss_switch'] && $fastchat_config['ssl_cert_file'] && $fastchat_config['ssl_key_file']) {
  23. $context = array(
  24. // 更多ssl选项 http://php.net/manual/zh/context.ssl.php
  25. 'ssl' => array(
  26. // 使用绝对路径
  27. 'local_cert' => $fastchat_config['ssl_cert_file'],
  28. 'local_pk' => $fastchat_config['ssl_key_file'],
  29. 'verify_peer' => false,
  30. // 'allow_self_signed' => true, //如果是自签名证书开启此选项
  31. )
  32. );
  33. $ssl_start = true;
  34. }
  35. $gateway = new Gateway("websocket://0.0.0.0:" . $fastchat_config['websocket_port'], $context);
  36. // 开始SSL
  37. if ($ssl_start) {
  38. $gateway->transport = 'ssl';
  39. }
  40. // gateway名称,status方便查看
  41. $gateway->name = 'FastChatGateway' . ($ssl_start ? '-wss' : '');
  42. // gateway进程数
  43. $gateway->count = $fastchat_config['gateway_process_number'];
  44. // 本机ip,分布式部署时使用内网ip
  45. $gateway->lanIp = '127.0.0.1';
  46. // 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
  47. // 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
  48. $gateway->startPort = $fastchat_config['internal_start_port'];
  49. // 服务注册地址
  50. $gateway->registerAddress = '127.0.0.1:' . $fastchat_config['register_port'];
  51. // 心跳间隔
  52. $gateway->pingInterval = 30;
  53. $gateway->pingNotResponseLimit = 1;
  54. // 心跳数据
  55. $gateway->pingData = '';
  56. // 如果不是在根目录启动,则运行runAll方法
  57. if (!defined('GLOBAL_START')) {
  58. Worker::runAll();
  59. }