Bug #75287 [Csd->ReO]: Builtin webserver crash after chdir in a shutdown function
| From: | nikic@php.net | Date: | Fri, 12 Jan 2018 17:20:07 +0000 |
| Subject: | Bug #75287 [Csd->ReO]: Builtin webserver crash after chdir in a shutdown function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213502@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75287&edit=1
ID: 75287
Updated by: nikic@php.net
Reported by: manuele dot menozzi at gmail dot com
Summary: Builtin webserver crash after chdir in a shutdown
function
-Status: Closed
+Status: Re-Opened
Type: Bug
Package: Built-in web server
Operating System: macOS / Linux Debian
PHP Version: 7.0.24
Block user comment: N
Private report: N
New Comment:
Reverted via https://github.com/php/php-src/commit/9e98e99a3a88f98d1377d5b2a43b7ad223d8a61f
due to BC break in patch release, see bug #75604.
Previous Comments:
------------------------------------------------------------------------
[2018-01-12 17:19:09] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9e98e99a3a88f98d1377d5b2a43b7ad223d8a61f
Log: Revert "Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown
function)"
------------------------------------------------------------------------
[2017-12-01 14:11:18] weirdan at gmail dot com
This not just fixed that bug, but also changed the way relative path to the router script is
treated. Previously it assumed the path to be relative to $CWD, now it's relative to document
root (set with the -t option).
It caused (easily fixed) breaks for scripts that were starting CLI server like this:
php -S 0.0.0.0:8888 -t public public/index.php.
Now they fail with:
PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
PHP Fatal error: Unknown: Failed opening required '<path
to>/public/public/index.php'
(note the duplicate 'public/public').
The fix is to start CLI server like this (router path is relative to doc root):
php -S 0.0.0.0:8888 -t public index.php
------------------------------------------------------------------------
[2017-10-15 02:30:06] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=816758eda2bcdd69ba505fb6bbb79124a7bf2254
Log: Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown function)
------------------------------------------------------------------------
[2017-09-29 17:20:31] manuele dot menozzi at gmail dot com
Description:
------------
Hi,
PHP's built-in webserver crashes if it's started with a router script with relative path
and in a shutdown function there is a chdir to a different directory than one where the router
script is.
Test script:
---------------
Create the file /home/user/router.php with the following content
<?php
function shutdownWithChdir() {
chdir('/tmp');
}
register_shutdown_function('shutdownWithChdir');
echo 'Hello World';
?>
Now in your terminal:
$ cd /home/user
$ php -S localhost:3000 router.php
Now perform the first request to the webserver and see that correctly returns "Hello
World". Then perform a second request.
Expected result:
----------------
You would expect to get "Hello World" even for the second request.
Actual result:
--------------
Instead you get:
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'router.php' (include_path='.:')
in Unknown on line 0
For every subsequent request. If you restart the webserver you'll get the same result: first
request ok, subsequent requests error.
This happens only if the chdir is done inside a "shutdown function" not if it's done
in the "normal" script execution.
I can confirm this bug on PHP 5.6, 7.0 and 7.1 (I do not remember the exact versions numbers) and I
don't think it's related to the #74496.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75287&edit=1