diff --git a/src/Command/Serve.php b/src/Command/Serve.php
index 3521df35a..00cc6010a 100644
--- a/src/Command/Serve.php
+++ b/src/Command/Serve.php
@@ -133,19 +133,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
['BOX_REQUIREMENT_CHECKER' => '0'] // prevents double check (build then serve)
);
- if ($this->getBuilder()->isDebug()) {
- $output->writeln(sprintf('Process: %s', implode(' ', $buildProcessArguments)));
- }
-
$buildProcess->setTty(Process::isTtySupported());
$buildProcess->setPty(Process::isPtySupported());
$buildProcess->setTimeout(3600 * 2); // timeout = 2 minutes
- $processOutputCallback = function ($type, $data) use ($output) {
- $output->write($data, false, OutputInterface::OUTPUT_RAW);
+ $processOutputCallback = function ($type, $buffer) use ($output) {
+ $output->write($buffer, false, OutputInterface::OUTPUT_RAW);
};
// (re)builds before serve
+ $output->writeln(sprintf('Build process: %s', implode(' ', $buildProcessArguments)), OutputInterface::VERBOSITY_DEBUG);
$buildProcess->run($processOutputCallback);
if ($buildProcess->isSuccessful()) {
Util\File::getFS()->dumpFile(Util::joinFile($this->getPath(), self::TMP_DIR, 'changes.flag'), time());
@@ -176,15 +173,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
pcntl_signal(SIGINT, [$this, 'tearDownServer']);
pcntl_signal(SIGTERM, [$this, 'tearDownServer']);
}
- $output->writeln(
- sprintf('Starting server (%s:%d>)...', $host, $port, $host, $port)
- );
- $process->start();
+ $output->writeln(sprintf('Server process: %s', $command), OutputInterface::VERBOSITY_DEBUG);
+ $output->writeln(sprintf('Starting server (%s:%d>)...', $host, $port, $host, $port));
+ $process->start(function ($type, $buffer) {
+ if ($type === Process::ERR) {
+ error_log($buffer, 3, Util::joinFile($this->getPath(), self::TMP_DIR, 'errors.log'));
+ }
+ });
if ($open) {
$output->writeln('Opening web browser...');
Util\Plateform::openBrowser(sprintf('http://%s:%s', $host, $port));
}
while ($process->isRunning()) {
+ sleep(1); // wait for server is ready
+ if (!fsockopen($host, (int) $port)) {
+ $output->writeln('Server is not ready.');
+
+ return 1;
+ }
$watcher = $resourceWatcher->findChanges();
if ($watcher->hasChanges()) {
// prints deleted/new/updated files in debug mode
@@ -217,6 +223,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('Server is runnning...');
}
}
+ if ($process->getExitCode() > 0) {
+ $output->writeln(sprintf('%s', trim($process->getErrorOutput())));
+ }
} catch (ProcessFailedException $e) {
$this->tearDownServer();
@@ -276,7 +285,7 @@ private function setUpServer(string $host, string $port): void
public function tearDownServer(): void
{
$this->output->writeln('');
- $this->output->writeln('Server stopped.');
+ $this->output->writeln('Server stopped.');
try {
Util\File::getFS()->remove(Util::joinFile($this->getPath(), self::TMP_DIR));