56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace app\command\admin;
|
|
|
|
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Argument;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
use Workerman\Worker as WmWorker;
|
|
|
|
class Worker extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->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('后台系统worker服务');
|
|
}
|
|
|
|
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('websocket://0.0.0.0:19980');
|
|
$adminWorker->onMessage = function ($connection, $message) {
|
|
var_dump($message);
|
|
$this->app->event->trigger('admin.websocket.Open', $connection, $message);
|
|
};
|
|
$adminWorker->onClose = function ($connection) {
|
|
$this->app->event->trigger('admin.websocket.Close', $connection);
|
|
};
|
|
|
|
WmWorker::runAll();
|
|
}
|
|
} |