« Previous Next »

Thread: What should getcwd() return when using fcgiext.dll and PHP?

Last post 12-09-2008 4:20 PM by tsimmons. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 12-09-2008, 1:16 PM

    • tsimmons
    • Not Ranked
    • Joined on 12-09-2008, 12:23 PM
    • Posts 2

    What should getcwd() return when using fcgiext.dll and PHP?

    This is on IIS 6.0. I am a bit confused and wonder if the FastCGI has a problem with the setting the startup directory or if I just have something set up improperly.

    When using straight-up PHP 5.2.8 (that is, *.php mapped to php-cgi.exe) if you create a php page with

    <?php echo getcwd()."<br />".dirname(__FILE__); ?> 

    and load it, both functions report the same directory, the folder where the PHP page is located.

    If you change IIS to use FastCGI with PHP configured in fcgiext.ini, the getcwd() reports "C:\Progra~1\PHP" while dirname(__FILE__) reports what is expected, the directory where the PHP file is located.

    This presents a problem when you have a PHP page (like WordPress) that does a require() expecting a file to be in the same directory as the PHP page, like this:

    <?php require('./wp-blog-header.php'); ?>

    Under FastCGI, the require files because it is looking for the file in "C:\Progra~1\PHP" ...

    My fcgiext.ini looks like this:

    [Types]
    php=PHP

    [PHP]
    ExePath=C:\Progra~1\PHP\php-cgi.exe
    InstanceMaxRequests=10000
    EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000

  • 12-09-2008, 4:05 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: What should getcwd() return when using fcgiext.dll and PHP?

    With CGI, the cwd for the CGI is the root of the virtual directory for the request - now for fastcgi, the same fastcgi process is used by multiple requests possibly from multiple vdirs/apps/sites, so it would not be right to set the cwd to match the root of the vdir for the first request - IIS has no way to set it beyond that.  So, the only sane thing for IIS to do is to set the cwd to where the fastcgi is located.

    Now, php itself could change the cwd to point to the respective vdir root etc for each request - I will try to pass along this suggestion to the php folks.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 12-09-2008, 4:20 PM In reply to

    • tsimmons
    • Not Ranked
    • Joined on 12-09-2008, 12:23 PM
    • Posts 2

    Re: What should getcwd() return when using fcgiext.dll and PHP?

    Thanks. That makes perfect sense, I was just wondering if there was a way to tell FastCGI to pass some magic parameter to php-cgi.exe telling it for each request what the initial directory should be so require() and include() requesting files from the current directory would work without forcing a cwd() in each PHP page.

    Thanks &
    Cheers,

    Toby

Page 1 of 1 (3 items)
Microsoft Communities