php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45125 FastCGI: option -C "chdir to the script's directory" doesn't work
Submitted: 2008-05-29 10:14 UTC Modified: 2008-09-02 14:35 UTC
From: florent at guiliani dot fr Assigned: dmitry (profile)
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.2.6 OS: GNU/Linux Ubuntu
Private report: No CVE-ID: None
 [2008-05-29 10:14 UTC] florent at guiliani dot fr
Description:
------------
The option -C "chdir to the script's directory" doesn't work when using PHP as FASTCGI server.

Due to this issue a first request will work and a second identical request will return "no input file specified"


Reproduce code:
---------------
$ strace -o strace.log /usr/bin/php5-cgi -C -b 9876
(run 2 identical requests)
$ grep "chdir\|index.php" strace.log
lstat64("/home/flgu/tmp/websvn/index.php", {st_mode=S_IFREG|0644, st_size=1656, ...}) = 0
open("/home/flgu/tmp/websvn/index.php", O_RDONLY|O_LARGEFILE) = 7
chdir("/home/flgu/tmp/websvn")          = 0
open("/home/flgu/tmp/websvn/websvn/index.php", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
$

Note the double "websvn/websvn" in the second open.

You can use this cgi to test it (adapt it with your own path):
#!/bin/bash

export SCRIPT_FILENAME=${REQUEST_URI/\/~flgu\/fast.cgi\//}

/home/flgu/tmp/fcgi-2.4.0/cgi-fcgi/cgi-fcgi -bind -connect localhost:9876


Expected result:
----------------
No chdir called and all request work

Actual result:
--------------
chdir called and only first request work

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-02 14:35 UTC] dmitry@php.net
At first note that -C means DO NOT chdir to the script's directory (it is not clear from the report).

"-C" option has effect only for command-line usage by design.
In case PHP supports it in FastCGI mode (as requested), we will allow incompatible behavior between FastCGI and other SAPIs, whish always do chdir to script's directory. So scripts, which written in assumption that this option work, won't work with other SAPIs. Also with this option enabled, any chdir() in PHP script may break all the following requests, because of invalid CWD expectation.

In your example (/usr/bin/php5-cgi -C -b 9876) "-C" just doesn't have effect.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 15:01:32 2024 UTC