diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index 0bcb42a7..ed62e4b6 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -12,7 +12,7 @@ class HttpServerCommand extends Command * * @var string */ - protected $signature = 'swoole:http {action : start|stop|restart|reload}'; + protected $signature = 'swoole:http {action : start|stop|restart|reload|infos}'; /** * The console command description. @@ -152,7 +152,7 @@ protected function reload() $isRunning = $this->killProcess($pid, SIGUSR1); - if (!$isRunning) { + if (! $isRunning) { $this->error('> failure'); exit(1); } @@ -160,6 +160,32 @@ protected function reload() $this->info('> success'); } + + /** + * Display PHP and Swoole misc info. + */ + protected function infos() + { + $this->showInfos(); + } + + /** + * Display PHP and Swoole miscs infos. + */ + protected function showInfos() + { + $pid = $this->getPid(); + $isRunning = $this->isRunning($pid); + + $this->table(['Name', 'Value'], [ + ['PHP Version', 'Version' => phpversion()], + ['Swoole Version', 'Version' => swoole_version()], + ['Laravel Version', $this->getApplication()->getVersion()], + ['Server Status', $isRunning ? 'Online' : 'Offline'], + ['PID', $isRunning ? $pid : 'None'], + ]); + } + /** * Initialize command action. */ @@ -167,8 +193,8 @@ protected function initAction() { $this->action = $this->argument('action'); - if (! in_array($this->action, ['start', 'stop', 'restart', 'reload'])) { - $this->error("Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart' or 'reload'."); + if (! in_array($this->action, ['start', 'stop', 'restart', 'reload', 'infos'])) { + $this->error("Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'."); exit(1); } } @@ -181,13 +207,13 @@ protected function initAction() */ protected function isRunning($pid) { - if (!$pid) { + if (! $pid) { return false; } Process::kill($pid, 0); - return !swoole_errno(); + return ! swoole_errno(); } /** @@ -206,7 +232,7 @@ protected function killProcess($pid, $sig, $wait = 0) $start = time(); do { - if (!$this->isRunning($pid)) { + if (! $this->isRunning($pid)) { break; } @@ -234,7 +260,7 @@ protected function getPid() if (file_exists($path)) { $pid = (int) file_get_contents($path); - if (!$pid) { + if (! $pid) { $this->removePidFile(); } else { $this->pid = $pid;