Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from swooletw/develop
Browse files Browse the repository at this point in the history
add infos command to show basic php and swoole miscs info
  • Loading branch information
albertcht authored Feb 24, 2018
2 parents 07c3ac2 + 49d689f commit 6171ae6
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/Commands/HttpServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -152,23 +152,49 @@ protected function reload()

$isRunning = $this->killProcess($pid, SIGUSR1);

if (!$isRunning) {
if (! $isRunning) {
$this->error('> failure');
exit(1);
}

$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.
*/
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);
}
}
Expand All @@ -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();
}

/**
Expand All @@ -206,7 +232,7 @@ protected function killProcess($pid, $sig, $wait = 0)
$start = time();

do {
if (!$this->isRunning($pid)) {
if (! $this->isRunning($pid)) {
break;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6171ae6

Please sign in to comment.