|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-08 23:00 UTC] adam at adammckaig dot com
when getcwd() is called from within an output handler function, it returns an incorrect path. the path returned is valid, and seems to be a previously used working directory.
the following script demonstrates the problem:
<?
header( "content-type: text/plain\n\n" );
chdir( "c:\\" );
function output_handler( $ob ) {
//chdir( "d:\\" );
$ob .= "2 - ".getcwd()."\n";
return $ob;
}
ob_start( "output_handler" );
print "1 - ".getcwd()."\n";
?>
the output from this script is:
1 - c:\
2 - c:\www\wwwroot\adammckaig.com
the second directory is valid, but totally unrelated to the demo script. the real oddity is that when the chdir( "d:\\" ); line is un-remmed, it works as expected:
1 - c:\
2 - d:\
but rem out the line again, and the output remains the same - but only for a minute or so! after about a minute, it has reset to the previous directory, c:\www\wwwroot\adammckaig.com! odd indeed.
i've tried the test script out on freebsd and linux web-servers, which both return the expected:
1 - /home/a/d/adammckaig/public_html/dev
2 - /home/a/d/adammckaig/public_html/dev
so the problem looks to be isolated to windows.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 20:00:01 2025 UTC |
the cvs snapshot has the same behaviour. after a bit more poking, i've found that the "register_shutdown_function" does the same thing. my slightly expanded test script: <? chdir( "c:\\' ); function output_handler( $ob ) { $ob .= "2 - ".getcwd()."<br />\n"; return $ob; } function shutdown_function() { print "3 - ".getcwd()."<br />\n"; } ob_start( "output_handler" ); register_shutdown_function( "shutdown_function" ); print "1 - ".getcwd()."<br />\n"; ?> now outputs: 1 - c:\ 2 - d:\program files\apache 3 - d:\program files\apache the paths returned are different from my first example, because the script was tested straight after restarting apache. if i execute some other scripts that changed the chdir, then execute the test script, the results are the same as my first example.