php.net |  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
Votes:7
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:
 [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:

<?
	set_time_limit(0);
	ignore_user_abort(0);

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

	echo "Body: ", `pwd`;

	register_shutdown_function ("Test");
?><BR>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-27 12:48 UTC] sniper@php.net
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] sniper@php.net
Another one related to #11831
 [2002-09-19 11:08 UTC] zeev@php.net
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] sniper@php.net
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.

<?
	set_time_limit(0);
	ignore_user_abort(0);

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

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

 [2004-08-27 11:35 UTC] vrana@php.net
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-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 01:01:59 2014 UTC