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 Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
13
|
|
|
use Symfony\Component\Process\Process; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* ServerCommand |
17
|
|
|
* |
18
|
|
|
* @package Bluzman\Command\Server |
19
|
|
|
* |
20
|
|
|
* @author Pavel Machekhin |
21
|
|
|
* @created 2013-05-24 19:23 |
22
|
|
|
*/ |
23
|
|
|
class StartCommand 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:start') |
33
|
15 |
|
// the short description shown while running "php bin/bluzman list" |
34
|
|
|
->setDescription('Launche a 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 start built-in PHP server') |
38
|
|
|
; |
39
|
15 |
|
|
40
|
15 |
|
$this->addOption('host', null, InputOption::VALUE_OPTIONAL, 'IP address of the server', '0.0.0.0'); |
41
|
15 |
|
$this->addOption('port', null, InputOption::VALUE_OPTIONAL, 'Port of the server', '8000'); |
42
|
15 |
|
$this->addOption('background', 'b', InputOption::VALUE_NONE, 'Run the server in the background'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param InputInterface $input |
47
|
|
|
* @param OutputInterface $output |
48
|
|
|
* @return int |
49
|
|
|
*/ |
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
51
|
|
|
{ |
52
|
|
|
$this->info('Running "server:start" command ... [' . $input->getOption('env') . ']'); |
53
|
|
|
|
54
|
|
|
$host = $input->getOption('host'); |
55
|
|
|
$port = $input->getOption('port'); |
56
|
|
|
$env = $input->getOption('env'); |
57
|
|
|
|
58
|
|
|
// setup BLUZ_ENV to environment |
59
|
|
|
// enable BLUZ_DEBUG |
60
|
|
|
// use public/routing.php |
61
|
|
|
$process = Process::fromShellCommandline( |
62
|
|
|
"export BLUZ_ENV=$env && export BLUZ_DEBUG=1 && export BLUZ_LOG=1 && php -S $host:$port routing.php", |
63
|
|
|
$this->getApplication()->getWorkingPath() . DS . 'public' |
|
|
|
|
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->write("Server has been started at <info>$host:$port</info>"); |
67
|
|
|
|
68
|
|
|
if ($input->getOption('background')) { |
69
|
|
|
$process->disableOutput(); |
70
|
|
|
$process->start(); |
71
|
|
|
|
72
|
|
|
$processId = $this->getProcessId($input->getOption('host'), $input->getOption('port')); |
73
|
|
|
|
74
|
|
|
$this->write("PID is <info>$processId</info>"); |
75
|
|
|
} else { |
76
|
|
|
while ($process instanceof Process) { |
77
|
|
|
if (!$process->isStarted()) { |
78
|
|
|
$process->start(); |
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
echo $process->getIncrementalOutput(); |
83
|
|
|
echo $process->getIncrementalErrorOutput(); |
84
|
|
|
|
85
|
|
|
if (!$process->isRunning() || $process->isTerminated()) { |
86
|
|
|
$process = false; |
87
|
|
|
|
88
|
|
|
$this->info('Server has been stopped.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
sleep(1); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
return 0; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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