Skip to content

Commit 7dfdb16

Browse files
committed
protect against deadlock for built-in php dev server
1 parent b66ed7f commit 7dfdb16

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/OAuth2Demo/Client/Controllers/RequestToken.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public static function addRoutes($routing)
1515

1616
public function requestTokenWithAuthCode(Application $app)
1717
{
18+
$this->testForBuiltInWebServer(); // if PHP's built in web server is being used, we cannot contiue
19+
1820
$twig = $app['twig']; // used to render twig templates
1921
$config = $app['parameters']; // the configuration for the current oauth implementation
2022
$urlgen = $app['url_generator']; // generates URLs based on our routing
@@ -49,6 +51,8 @@ public function requestTokenWithAuthCode(Application $app)
4951

5052
public function requestTokenWithUserCredentials(Application $app)
5153
{
54+
$this->testForBuiltInWebServer(); // if PHP's built in web server is being used, we cannot contiue
55+
5256
$twig = $app['twig']; // used to render twig templates
5357
$config = $app['parameters']; // the configuration for the current oauth implementation
5458
$urlgen = $app['url_generator']; // generates URLs based on our routing
@@ -81,4 +85,14 @@ public function requestTokenWithUserCredentials(Application $app)
8185

8286
return $twig->render('client/failed_token_request.twig', array('response' => $json ? $json : $response));
8387
}
88+
89+
public function testForBuiltInWebServer()
90+
{
91+
if (isset($_SERVER['SERVER_SOFTWARE']) && preg_match('/PHP \d+\.\d+\.\d+ Development Server/', $_SERVER['SERVER_SOFTWARE'])) {
92+
$message = 'As PHP\'s built-in web-server does not allow for concurrent requests, this will result in deadlock.';
93+
$message .= "<br /><br />";
94+
$message .= 'You must configure a virtualhost via Apache or another web server to continue. Sorry!';
95+
exit($message);
96+
}
97+
}
8498
}

0 commit comments

Comments
 (0)