start.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * run with command
  4. * php start.php start
  5. */
  6. namespace addons\fastchat\library\gatewayworker;
  7. ini_set('display_errors', 'on');
  8. use think\Config;
  9. use think\console\Command;
  10. use think\console\Input;
  11. use think\console\input\Argument;
  12. use think\console\input\Option;
  13. use think\console\Output;
  14. use think\Db;
  15. use think\Exception;
  16. use think\exception\PDOException;
  17. use Workerman\Worker;
  18. /**
  19. *
  20. */
  21. class start extends Command
  22. {
  23. protected function configure()
  24. {
  25. $this->setName('fastchat')
  26. ->addArgument('action', Argument::OPTIONAL, "action start [d]|stop|restart|status")
  27. ->addArgument('type', Argument::OPTIONAL, "d -d")
  28. ->setDescription('FastChat会话服务');
  29. }
  30. protected function execute(Input $input, Output $output)
  31. {
  32. global $argv;
  33. $action = trim($input->getArgument('action'));
  34. $type = trim($input->getArgument('type')) ? '-d' : '';
  35. $argv[0] = 'chat';
  36. $argv[1] = $action;
  37. $argv[2] = $type ? '-d' : '';
  38. $this->start();
  39. }
  40. private function start()
  41. {
  42. if (strpos(strtolower(PHP_OS), 'win') === 0) {
  43. exit("Windows下不支持窗口启动,请运行:/public/fastchat_start_for_win.bat\n");
  44. }
  45. // 检查扩展
  46. if (!extension_loaded('pcntl')) {
  47. exit("请安装 pcntl 扩展. 参见 http://doc3.workerman.net/appendices/install-extension.html\n");
  48. }
  49. if (!extension_loaded('posix')) {
  50. exit("请安装 posix 扩展. 参见 http://doc3.workerman.net/appendices/install-extension.html\n");
  51. }
  52. // 标记是全局启动
  53. define('GLOBAL_START', 1);
  54. require_once __DIR__ . '/vendor/autoload.php';
  55. // 加载所有Applications/*/start.php,以便启动所有服务
  56. foreach (glob(__DIR__ . '/Applications/*/start*.php') as $start_file) {
  57. require_once $start_file;
  58. }
  59. // 运行所有服务
  60. Worker::runAll();
  61. }
  62. }