php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80527 Current directory deleted before shutdown_function - File functions affected
Submitted: 2020-12-17 14:30 UTC Modified: 2021-01-07 14:21 UTC
From: heavy-traffic-website at yopmail dot com Assigned: cmb (profile)
Status: Duplicate Package: *Directory/Filesystem functions
PHP Version: 8.0.0 OS: Debian 11
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: heavy-traffic-website at yopmail dot com
New email:
PHP Version: OS:

 

 [2020-12-17 14:30 UTC] heavy-traffic-website at yopmail dot com
Description:
------------
Files functions doesn't work with relative paths since the current working directory is deleted during the "exit" line. Is this a bug or a feature ? :-)

Test script:
---------------
function debug_cwd(int $i)
{
    syslog(LOG_DEBUG, "getcwd [$i] -> " . getcwd());
}

function shutdown()
{
    debug_cwd(4);
    chdir('/var/www/website');
    debug_cwd(5);
}

chdir('/var/www/website')
debug_cwd(1);
register_shutdown_function('shutdown');
debug_cwd(2);
fastcgi_finish_request();
debug_cwd(3);
exit;
debug_cwd(6); // will not be displayed


Expected result:
----------------
$> tail /var/log/syslog
Dec 17 15:09:43 hosting php: getcwd [1] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [2] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [3] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [4] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [5] -> /var/www/website

Actual result:
--------------
$> tail /var/log/syslog
Dec 17 15:09:43 hosting php: getcwd [1] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [2] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [3] -> /var/www/website
Dec 17 15:09:43 hosting php: getcwd [4] -> /
Dec 17 15:09:43 hosting php: getcwd [5] -> /var/www/website

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-17 14:34 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: *Directory/Filesystem functions -Assigned To: +Assigned To: cmb
 [2020-12-17 14:52 UTC] heavy-traffic-website at yopmail dot com
I only use PHP-FPM with Haproxy with FCGI, not Apache.

I understand there is a little notice that inform it can change during the shutdown function... but... is this normal for our use / need ? Probably not.

Why don't you are able to restore the CWD during the shutdown function ? Since i am able to write a one-line fix ; it should be evaluated the feature to not change the CWD during the shutdown function.
 [2020-12-17 14:54 UTC] heavy-traffic-website at yopmail dot com
-Type: Bug +Type: Feature/Change Request
 [2020-12-17 14:54 UTC] heavy-traffic-website at yopmail dot com
Not a Bug ? -> Feature
 [2020-12-17 14:59 UTC] cmb@php.net
-Status: Not a bug +Status: Open -Assigned To: cmb +Assigned To:
 [2021-01-07 14:21 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-01-07 14:21 UTC] cmb@php.net
Well, actually a duplicate of bug #40661.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC