8000 print error message if server couldn't be started · symfony/symfony@84a5ae6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84a5ae6

Browse files
committed
print error message if server couldn't be started
1 parent 86354c7 commit 84a5ae6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php

Lines changed: 20 additions & 2 deletions
167
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
9191
}
9292

9393
$env = $this->getContainer()->getParameter('kernel.environment');
94+
$address = $input->getArgument('address');
95+
96+
if ($this->isOtherServerProcessRunning($address)) {
97+
$output->writeln(sprintf('<error>A process is already listening on http://%s.</error>', $address));
98+
99+
return 1;
100+
}
94101

95102
if ('prod' === $env) {
96103
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
@@ -104,8 +111,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
104111
return 1;
105112
}
106113

107-
$address = $input->getArgument('address');
108-
109114
if ($pid > 0) {
110115
$output->writeln(sprintf('<info>Web server listening on http://%s</info>', $address));
111116

@@ -144,6 +149,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
144149
}
145150
}
146151

152+
private function isOtherServerProcessRunning($address)
153+
{
154+
$lockFile = $this->getLockFile($address);
155+
156+
if (file_exists($lockFile)) {
157+
return true;
158+
}
159+
160+
list($hostname, $port) = explode(':', $address);
161+
162+
return @fsockopen($hostname, $port, $errno, $errstr, 5);
163+
}
164+
147165
/**
148166
* Creates a process to start PHP's built-in web server.
149
*

0 commit comments

Comments
 (0)
0