Edit report at https://bugs.php.net/bug.php?id=64951&edit=1
ID: 64951 Comment by: a dot panek at brainsware dot org Reported by: a dot panek at brainsware dot org Summary: SCRIPT_NAME acts strange Status: Not a bug Type: Bug Package: Built-in web server Operating System: Linux & Windows PHP Version: 5.4.15 Assigned To: ab Block user comment: N Private report: N New Comment: 1) I am using the router script according to the example in the documentation: http://php.net/manual/en/features.commandline.webserver.php#example-381 ("Example #4 Checking for CLI Web Server Use", "To reuse a framework router script during development with the CLI web server and later also with a production web server:") This implies that I can reuse my current index.php, put in checks whether a file exists, and keep the rest as-is. I can't do this right now because SCRIPT_NAME doesn't behave as-is, but instead as if I had Apache + mod_rewrite enabled - as you said. I can't seem to find that behaviour documented anywhere? That seems like either a bug in the documentation or the server. 2) If my router script is not called "index.php" but something else, SCRIPT_NAME *always* holds the URI instead of the actual script path. I haven't seen that documented either. (And it feels wrong to have that behaviour without any documentation about it) 3a) If I do not use a router script and try to access a URI with a file extension (like /something.json), the server always returns a 404 if given URI doesn't point to an actual file. Even if this is not considered a bug, it's not good to be that unpredictable. Previous Comments: ------------------------------------------------------------------------ [2013-06-03 07:29:40] a...@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Using the router script in the command line is the same as using mod_rewrite with apache, basically something like this RewriteEngine On RewriteRule ^/hellou$ /hello.php [L] is equivalent to php -S localhost:8080 -t. hello.php With this, requesting /hellou under apache will result $_SERVER['SCRIPT_NAME'] => /hellou __FILE__ => full path to hello.php If you ommit the router script, you'll get the apache behaviour without mod_rewrite. To do so, in your example php -S localhost:8080 -t. The current document root will be like a normal htdocs with apache. ------------------------------------------------------------------------ [2013-05-31 07:28:09] a dot panek at brainsware dot org Description: ------------ When sending a request that has a file extension OR the request doesn't go to a index.php (a test.php, e.g.), the SCRIPT_NAME holds the URI instead of the actual current script name as documented here http://php.net/manual/en/reserved.variables.server.php "Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file." So basically the built-in server doesn't act as documented except when you use a file called "index.php" as router script and don't use a file extension in your URI. I tested this on Linux and Windows resulting in the exact same behaviour. Test script: --------------- <?php # index.php # # php -S localhost:8080 -t. index.php # # curl -i -X GET -H 'Accept: application/json' localhost:8080/something.json # -> '/something.json' # curl -i -X GET -H 'Accept: application/json' localhost:8080/something # -> '/index.php # # php -S localhost:8080 -t. test.php # -> always the uri echo $_SERVER['SCRIPT_NAME']; ?> Expected result: ---------------- /index.php Actual result: -------------- /something.json ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64951&edit=1