Bug #75287 [NEW]: Builtin webserver crash after chdir in a shutdown function
| From: | manuele dot menozzi at gmail dot com | Date: | Fri, 29 Sep 2017 17:20:39 +0000 |
| Subject: | Bug #75287 [NEW]: Builtin webserver crash after chdir in a shutdown function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-211460@lists.php.net to get a copy of this message | ||
From: manuele dot menozzi at gmail dot com
Operating system: macOS / Linux Debian
PHP version: 7.0.24
Package: Built-in web server
Bug Type: Bug
Bug description:Builtin webserver crash after chdir in a shutdown function
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 bug report at https://bugs.php.net/bug.php?id=75287&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75287&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75287&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75287&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75287&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75287&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75287&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75287&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75287&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75287&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75287&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75287&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75287&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75287&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75287&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75287&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75287&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75287&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75287&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75287&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75287&r=mysqlcfg