php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22132 getcwd() returns the wrong cwd in output handler function
Submitted: 2003-02-08 23:00 UTC Modified: 2003-03-04 20:38 UTC
From: adam at adammckaig dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.2-dev OS: Windows 2000
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: adam at adammckaig dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-13 07:50 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Cannot replicate using the latest CVS snapshot.
 [2003-02-15 20:24 UTC] adam at adammckaig dot com
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.
 [2003-03-04 20:37 UTC] sniper@php.net
Under what SAPI does it happen? Have you tried CLI?

 [2003-03-04 20:38 UTC] sniper@php.net
Nevermind that previous comment, it's an Apache bug, not PHP bug.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 17:01:33 2025 UTC