Bug #75287 [Opn->Csd]: Builtin webserver crash after chdir in a shutdown function
| From: | laruence@php.net | Date: | Sun, 15 Oct 2017 02:30:09 +0000 |
| Subject: | Bug #75287 [Opn->Csd]: Builtin webserver crash after chdir in a shutdown function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211686@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: laruence@php.net
Reported by: manuele dot menozzi at gmail dot com
Summary: Builtin webserver crash after chdir in a shutdown
function
-Status: Open
+Status: Closed
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:
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)
Previous Comments:
------------------------------------------------------------------------
[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