diff --git a/app/command/Crontab.php b/app/command/admin/Crontab.php similarity index 97% rename from app/command/Crontab.php rename to app/command/admin/Crontab.php index efa6dbb..3568486 100644 --- a/app/command/Crontab.php +++ b/app/command/admin/Crontab.php @@ -1,14 +1,14 @@ setName('crontab') + $this->setName('admin:crontab') ->setDescription('定时任务'); } diff --git a/app/command/admin/Worker.php b/app/command/admin/Worker.php new file mode 100644 index 0000000..4ae6a74 --- /dev/null +++ b/app/command/admin/Worker.php @@ -0,0 +1,51 @@ +setName('admin:worker') + ->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start') + ->addOption('mode', 'm', Option::VALUE_OPTIONAL, 'Run the workerman server in daemon mode.') + ->setDescription('the workerman admin command'); + } + + protected function execute(Input $input, Output $output) + { + $output->writeln('convert start'); + + $action = $input->getArgument('action'); + $mode = $input->getOption('mode'); + + + global $argv; + + $argv = []; + + array_unshift($argv, 'think', $action); + if ($mode == 'd') { + $argv[] = '-d'; + } else if ($mode == 'g') { + $argv[] = '-g'; + } + /* + * 创建后台ws链接 + */ + $adminWorker = new WmWorker('ws://0.0.0.0:19980'); + $adminWorker->onMessage = [AdminWorker::class, 'onMessage']; + $adminWorker->onClose = [AdminWorker::class, 'onClose']; + + WmWorker::runAll(); + } +} \ No newline at end of file diff --git a/app/http/worker/AdminWorker.php b/app/http/worker/AdminWorker.php new file mode 100644 index 0000000..7b3c3dd --- /dev/null +++ b/app/http/worker/AdminWorker.php @@ -0,0 +1,15 @@ +send(json_encode($data)); + } + + public function onClose() + { + + } +} \ No newline at end of file diff --git a/config/console.php b/config/console.php index 05c9ba3..ca87d9c 100644 --- a/config/console.php +++ b/config/console.php @@ -5,6 +5,7 @@ return [ // 指令定义 'commands' => [ - \app\command\Crontab::class, + \app\command\admin\Crontab::class, + \app\command\admin\Worker::class, ], ];