'start', 'worker:stop' => 'stop', 'worker:restart' => 'restart', // 'worker:reload' => 'reload', // 'worker:status' => 'status', ]; protected static $description = [ 'worker:start' => '启动 携带参数-d 后台启动', 'worker:stop' => '停止', 'worker:restart' => '重启 携带参数-d 后台启动', // 'worker:reload' => '平滑重启', // 'worker:status' => '查看进程运行状态', ]; /** * undocumented function * * @return void * @author **/ public function __construct() { $this->manage = new taskmgr_swprocess_manage; } /** * 启动 */ public function start() { global $argv; if ($this->manage->getPid()) { taskmgr_swconsole_output::warning('已启动不可重复启动' . PHP_EOL); exit(); } if (isset($argv[2]) && $argv[2] == '-d') { taskmgr_swconsole_output::warning('以守护进程方式启动,请去日志中查询详细信息,日志目录地址:./logs/' . PHP_EOL); Process::daemon(); taskmgr_swprocess_conf::setDaemon(true); } taskmgr_log::info('正在启动中,请稍后....', [], 'system'); $this->manage->run(); // $this->wait(); } /** * 重启 * @throws \Exception */ public function restart() { $this->stop(); $this->start(); } /** * 停止 * @param false $is_start * @throws \Exception */ public function stop() { $pid = $this->manage->getPid(); if ($pid) { taskmgr_swconsole_output::normal('正在停止....' . PHP_EOL); while (true) { Process::kill($pid, SIGTERM); usleep(1000000); if (!$this->manage->getPid()) { taskmgr_swconsole_output::normal("已停止...\n"); return true; } } } taskmgr_swconsole_output::normal('任务未启动无需停止' . PHP_EOL); return; } }