1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Bluz PHP Team |
5
|
|
|
* @link https://github.com/bluzphp/bluzman |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Bluzman\Command\Server; |
9
|
|
|
|
10
|
|
|
use Bluzman\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
13
|
|
|
use Symfony\Component\Process\Process; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* StatusCommand |
17
|
|
|
* |
18
|
|
|
* @package Bluzman\Command\Server |
19
|
|
|
* |
20
|
|
|
* @author Pavel Machekhin |
21
|
|
|
* @created 2013-06-17 14:52 |
22
|
|
|
*/ |
23
|
|
|
class StatusCommand extends AbstractServerCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Command configuration |
27
|
15 |
|
*/ |
28
|
|
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
15 |
|
// the name of the command (the part after "bin/bluzman") |
32
|
|
|
->setName('server:status') |
33
|
15 |
|
// the short description shown while running "php bin/bluzman list" |
34
|
|
|
->setDescription('Get the status of built-in PHP server') |
35
|
|
|
// the full command description shown when running the command with |
36
|
15 |
|
// the "--help" option |
37
|
|
|
->setHelp('This command allows you to check built-in PHP server') |
38
|
15 |
|
; |
39
|
15 |
|
$this->addOption('host', null, InputOption::VALUE_OPTIONAL, 'IP address of the server', '0.0.0.0'); |
40
|
15 |
|
$this->addOption('port', null, InputOption::VALUE_OPTIONAL, 'Port of the server', '8000'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param InputInterface $input |
45
|
|
|
* @param OutputInterface $output |
46
|
|
|
* @return int |
47
|
|
|
*/ |
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
49
|
|
|
{ |
50
|
|
|
$this->info('Running "server:status" command'); |
51
|
|
|
try { |
52
|
|
|
$host = $input->getOption('host'); |
53
|
|
|
$port = $input->getOption('port'); |
54
|
|
|
|
55
|
|
|
$pid = $this->getProcessId($host, $port) ?: false; |
56
|
|
|
|
57
|
|
|
if (!$pid) { |
58
|
|
|
throw new NotRunningException(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$process = Process::fromShellCommandline("ps -p $pid -o comm="); |
62
|
|
|
$process->run(); |
63
|
|
|
|
64
|
|
|
$processOutput = $process->getOutput(); |
65
|
|
|
|
66
|
|
|
if (empty($processOutput)) { |
67
|
|
|
throw new NotRunningException(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->write("Server <info>$host:$port</info> is running. PID is <info>$pid</info>"); |
71
|
|
|
return 0; |
72
|
|
|
} catch (NotRunningException $e) { |
73
|
|
|
$this->comment('Server is not running'); |
74
|
|
|
return (int) $e->getCode(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths