|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40661 cwd is reset when shutdown handler runs
Submitted: 2007-02-27 14:44 UTC Modified: 2021-10-11 13:52 UTC
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: Assigned:
Status: Open Package: Apache related
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-02-27 14:44 UTC]
When this script is run with the Apache1 sapi the second CWD is reset to /.

This is an issue for both php 4.4.4 and php 5.2.1rc3.

Reproduce code:
echo "CWD = ", getcwd(), "\n";

function handler()
    echo "CWD = ", getcwd(), "\n";
    echo dirname( __FILE__ ), "\n";

register_shutdown_function( 'handler' );


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-27 15:00 UTC]
I disagree, there is no reason why PHP can't reset the CWD to the correct directory when a shutdown handler is run. That is what I would expect to happen.
 [2007-07-11 12:35 UTC]
Making sure this doesn't slip through the cracks..also found in PHP 5.2
 [2011-04-08 21:22 UTC]
-Package: Feature/Change Request +Package: Apache related
 [2021-10-11 13:52 UTC]
> Making sure this doesn't slip through the cracks..

Didn't work. :)

While it shouldn't be hard to restore the CWD during the shutdown
handler, I wonder whether we should do it.  After that long time,
most code likely has adapted to do this manually (or doesn't use
relative paths in the first place), and some code may even use the
CWD reset on purpose (BC break).

Anyhow, this change is unlikely to happen, unless somebody submits
a PR.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Sep 26 18:01:25 2023 UTC