Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 6171ae6

Browse files
authored
Merge pull request #5 from swooletw/develop
add infos command to show basic php and swoole miscs info
2 parents 07c3ac2 + 49d689f commit 6171ae6

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/Commands/HttpServerCommand.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class HttpServerCommand extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'swoole:http {action : start|stop|restart|reload}';
15+
protected $signature = 'swoole:http {action : start|stop|restart|reload|infos}';
1616

1717
/**
1818
* The console command description.
@@ -152,23 +152,49 @@ protected function reload()
152152

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

155-
if (!$isRunning) {
155+
if (! $isRunning) {
156156
$this->error('> failure');
157157
exit(1);
158158
}
159159

160160
$this->info('> success');
161161
}
162162

163+
164+
/**
165+
* Display PHP and Swoole misc info.
166+
*/
167+
protected function infos()
168+
{
169+
$this->showInfos();
170+
}
171+
172+
/**
173+
* Display PHP and Swoole miscs infos.
174+
*/
175+
protected function showInfos()
176+
{
177+
$pid = $this->getPid();
178+
$isRunning = $this->isRunning($pid);
179+
180+
$this->table(['Name', 'Value'], [
181+
['PHP Version', 'Version' => phpversion()],
182+
['Swoole Version', 'Version' => swoole_version()],
183+
['Laravel Version', $this->getApplication()->getVersion()],
184+
['Server Status', $isRunning ? 'Online' : 'Offline'],
185+
['PID', $isRunning ? $pid : 'None'],
186+
]);
187+
}
188+
163189
/**
164190
* Initialize command action.
165191
*/
166192
protected function initAction()
167193
{
168194
$this->action = $this->argument('action');
169195

170-
if (! in_array($this->action, ['start', 'stop', 'restart', 'reload'])) {
171-
$this->error("Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart' or 'reload'.");
196+
if (! in_array($this->action, ['start', 'stop', 'restart', 'reload', 'infos'])) {
197+
$this->error("Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'.");
172198
exit(1);
173199
}
174200
}
@@ -181,13 +207,13 @@ protected function initAction()
181207
*/
182208
protected function isRunning($pid)
183209
{
184-
if (!$pid) {
210+
if (! $pid) {
185211
return false;
186212
}
187213

188214
Process::kill($pid, 0);
189215

190-
return !swoole_errno();
216+
return ! swoole_errno();
191217
}
192218

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

208234
do {
209-
if (!$this->isRunning($pid)) {
235+
if (! $this->isRunning($pid)) {
210236
break;
211237
}
212238

@@ -234,7 +260,7 @@ protected function getPid()
234260
if (file_exists($path)) {
235261
$pid = (int) file_get_contents($path);
236262

237-
if (!$pid) {
263+
if (! $pid) {
238264
$this->removePidFile();
239265
} else {
240266
$this->pid = $pid;

0 commit comments

Comments
 (0)