diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php
index 977de6ef88..7808560835 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php
@@ -91,6 +91,19 @@ EOF
}
$env = $this->getContainer()->getParameter('kernel.environment');
+ $address = $input->getArgument('address');
+
+ if (false === strpos($address, ':')) {
+ $output->writeln('The address has to be of the form bind-address:port.');
+
+ return 1;
+ }
+
+ if ($this->isOtherServerProcessRunning($address)) {
+ $output->writeln(sprintf('A process is already listening on http://%s.', $address));
+
+ return 1;
+ }
if ('prod' === $env) {
$output->writeln('Running PHP built-in server in production environment is NOT recommended!');
@@ -104,8 +117,6 @@ EOF
return 1;
}
- $address = $input->getArgument('address');
-
if ($pid > 0) {
$output->writeln(sprintf('Web server listening on http://%s', $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.
*