start_gateway.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. use \Workerman\Autoloader;
  17. require_once __DIR__ . '/../../vendor/autoload.php';
  18. // gateway 进程
  19. $gateway = new Gateway("Websocket://0.0.0.0:8282");
  20. // 设置名称,方便status时查看
  21. $gateway->name = 'pushMessage';
  22. // 设置进程数,gateway进程数建议与cpu核数相同
  23. $gateway->count = 1;
  24. // 分布式部署时请设置成内网ip(非127.0.0.1)
  25. $gateway->lanIp = '127.0.0.1';
  26. // 内部通讯起始端口。假如$gateway->count=4,起始端口为2300
  27. // 则一般会使用2300 2301 2302 2303 4个端口作为内部通讯端口
  28. $gateway->startPort = 2300;
  29. // 心跳间隔
  30. $gateway->pingInterval = 20;
  31. // 心跳数据
  32. $gateway->pingData = '{"type":"ping"}';
  33. // 服务注册地址
  34. $gateway->registerAddress = '127.0.0.1:1236';
  35. // 如果不是在根目录启动,则运行runAll方法
  36. if(!defined('GLOBAL_START'))
  37. {
  38. Worker::runAll();
  39. }