Sgateway.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller\fastchat;
  3. use GatewayWorker\Gateway;
  4. use Workerman\Worker;
  5. // 自动加载类
  6. require_once __DIR__ . '/../../../../addons/fastchat/library/GatewayWorker/vendor/autoload.php';
  7. /**
  8. * Win下启动 gateway服务 专用类
  9. */
  10. class Sgateway
  11. {
  12. function __construct()
  13. {
  14. // gateway 进程
  15. $context = array(/*'ssl' => array(
  16. // 使用绝对路径
  17. 'local_cert' => '/www/wwwroot/soket.cn/vendor/workerman/cert/soket.cn.pem', // 也可以是crt文件
  18. 'local_pk' => '/www/wwwroot/soket.cn/vendor/workerman/cert/soket.cn.key',
  19. 'verify_peer' => false,
  20. // 'allow_self_signed' => true, //如果是自签名证书开启此选项
  21. )*/
  22. );
  23. $fastchat_config = get_addon_config('fastchat');
  24. $gateway = new Gateway("websocket://0.0.0.0:" . $fastchat_config['websocket_port'], $context);
  25. // 开始SSL
  26. if ($fastchat_config['wss_switch']) {
  27. $gateway->transport = 'ssl';
  28. }
  29. // gateway名称,status方便查看
  30. $gateway->name = 'FastChatGateway';
  31. // gateway进程数
  32. $gateway->count = $fastchat_config['gateway_process_number'];
  33. // 本机ip,分布式部署时使用内网ip
  34. $gateway->lanIp = '127.0.0.1';
  35. // 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
  36. // 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
  37. $gateway->startPort = $fastchat_config['internal_start_port'];
  38. // 服务注册地址
  39. $gateway->registerAddress = '127.0.0.1:' . $fastchat_config['register_port'];
  40. // 心跳间隔
  41. $gateway->pingInterval = 30;
  42. $gateway->pingNotResponseLimit = 1;
  43. // 心跳数据
  44. $gateway->pingData = '';
  45. // 如果不是在根目录启动,则运行runAll方法
  46. if (!defined('GLOBAL_START')) {
  47. Worker::runAll();
  48. }
  49. }
  50. }