|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14251 register_shutdown_function bug
Submitted: 2001-11-27 12:04 UTC Modified: 2004-08-27 11:35 UTC
Avg. Score:4.1 ± 1.4
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:4 (57.1%)
From: se at e-kazan dot ru Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.0 OS: Linux Mandrake 8.0
Private report: No CVE-ID: None
 [2001-11-27 12:04 UTC] se at e-kazan dot ru
Current directory in main program body and into shutdown function is not same. Sometimes its changes to '/' or something else.

Try to execute this script and reload page some times:


	function Test()
		echo "Shutdown function: ", `pwd`;

	echo "Body: ", `pwd`;

	register_shutdown_function ("Test");


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-27 12:48 UTC]
Reproduced. Seems like cwd changes to / always.

 [2002-08-05 16:48 UTC] john at vbulletin dot com
I have reproduced this too on PHP 4.2.2 and Linux RH 6.2. However it does not seem to occur in Windows.

Workaround by putting getcwd() into a global variable before shutdown then using chdir() in the shutdown_function.
 [2002-09-03 18:35 UTC]
Another one related to #11831
 [2002-09-19 11:08 UTC]
This isn't related to #11831.

It has to do with the fact that by the time we're shutting down, we're no longer in the request context, but rather, in Apache's shutdown context.  Apache is probably changing directory to / at this stage.

I'm not sure why this is tagged as critical, I'm not sure whether this should be 'fixed'.  My recommendation is to move it to 'Analyzed' status.
 [2002-09-19 21:07 UTC]
IIRC (!) this was some problem with the cwd funcs in TSRM.
Can't remember now what exactly it was..

(it works in windows but not in *nix)

 [2002-11-12 08:19 UTC] x at x dot anon
It's very serios bug. Try this samle and try to find out 'out.txt' file.


	function Test()
		$fp = fopen ('out.txt', 'w');
		fwrite ($fp, 'TEST');;
		fclose ($fp);

	register_shutdown_function ("Test");
 [2003-02-25 02:44 UTC]
It's Apache that changes the pwd, not PHP.

 [2004-08-27 11:35 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Working directory of the script can change inside the shutdown function under some web servers, e.g. Apache."
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu May 28 02:01:25 2020 UTC