Skip to content

Commit

Permalink
Implemented FR #60850 (Built in web server does not set $_SERVER['SCR…
Browse files Browse the repository at this point in the history
…IPT_FILENAME'] when using router)
  • Loading branch information
laruence committed Mar 11, 2012
1 parent 024420e commit 4ff1126
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC)
sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath TSRMLS_CC);
if (SG(request_info).path_translated) {
sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated TSRMLS_CC);
} else if (client->server->router) {
char *temp;
spprintf(&temp, 0, "%s/%s", client->server->document_root, client->server->router);
sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", temp TSRMLS_CC);
efree(temp);
}
if (client->request.path_info) {
sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info TSRMLS_CC);
Expand Down
44 changes: 44 additions & 0 deletions sapi/cli/tests/php_cli_server_017.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
Implement Req #60850 (Built in web server does not set $_SERVER['SCRIPT_FILENAME'] when using router)
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
include "php_cli_server.inc";
php_cli_server_start(<<<PHP
var_dump(\$_SERVER['SCRIPT_FILENAME']);
PHP
);

list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
$port = intval($port)?:80;

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}

if(fwrite($fp, <<<HEADER
POST / HTTP/1.1
Host: {$host}
HEADER
)) {
while (!feof($fp)) {
echo fgets($fp);
}
}

fclose($fp);
?>
--EXPECTF--
HTTP/1.1 200 OK
Host: %s
Connection: close
X-Powered-By: %s
Content-type: text/html

string(%d) "%s/tests/index.php"

0 comments on commit 4ff1126

Please sign in to comment.