bug #12258 [FrameworkBundle] print error message if server couldn't be started (xabbuh)
This PR was submitted for the master branch but it was merged into the 2.6 branch instead (closes #12258).
Discussion
----------
[FrameworkBundle] print error message if server couldn't be started
As @weaverryan noticed in symfony/symfony-docs#4005, the `server:run` command would provide you with a success message even if there were a web server already listening.
Commits
-------
6b2537b
print error message if server couldn't be started
This commit is contained in:
commit
fb1732aa64
@ -91,6 +91,19 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
$env = $this->getContainer()->getParameter('kernel.environment');
|
$env = $this->getContainer()->getParameter('kernel.environment');
|
||||||
|
$address = $input->getArgument('address');
|
||||||
|
|
||||||
|
if (false === strpos($address, ':')) {
|
||||||
|
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isOtherServerProcessRunning($address)) {
|
||||||
|
$output->writeln(sprintf('<error>A process is already listening on http://%s.</error>', $address));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ('prod' === $env) {
|
if ('prod' === $env) {
|
||||||
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
|
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
|
||||||
@ -104,8 +117,6 @@ EOF
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$address = $input->getArgument('address');
|
|
||||||
|
|
||||||
if ($pid > 0) {
|
if ($pid > 0) {
|
||||||
$output->writeln(sprintf('<info>Web server listening on http://%s</info>', $address));
|
$output->writeln(sprintf('<info>Web server listening on http://%s</info>', $address));
|
||||||
|
|
||||||
@ -144,6 +155,27 @@ EOF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isOtherServerProcessRunning($address)
|
||||||
|
{
|
||||||
|
$lockFile = $this->getLockFile($address);
|
||||||
|
|
||||||
|
if (file_exists($lockFile)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
list($hostname, $port) = explode(':', $address);
|
||||||
|
|
||||||
|
$fp = @fsockopen($hostname, $port, $errno, $errstr, 5);
|
||||||
|
|
||||||
|
if (false !== $fp) {
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a process to start PHP's built-in web server.
|
* Creates a process to start PHP's built-in web server.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user