On Mon, 20 Jan 2003, Joe Laffey wrote:

> I just installed PHP 4.3.0 on 3 different systems. I built apache 1.3.27
> and php with the exact same configure strings on each of the three
> systems. I am having some strange issues with the cwd.
>
> All systems have the same php.ini and almost identical httpd.conf files.
> The directory structure has been mirrored among the three using rsync with
> persmission ad users intact. So these all match.
>
> I have a directory "mydir" with a subdirectory "subdir".
>
> The script I am executing is "myscript.php" inside "mydir".
>
> On linux:
>  I can include("subdir/filename") and it works fine.
>
> On Mac OS X (client):
>  include("subdir/filename") fails (file not found)
>  include("./subdir/filename") works
>
> On NetBSd 1.5.3 Mac 68k (yeah, old)
>  include("subdir/filename") fails (file not found)
>  include("./subdir/filename") fails (file not found)
>  Only including the full path works
>  echo()ing the getcwd() returns an empty string
>
>
> Including the full path works on all (so that is what I am using).
>
> Any thoughts as to why this is happening, or how to avoid it. Note that
> the files are inside a parent directory "/web". FWIW, web is world
> executable, but not world readable.
>
> I just tested it with the "/web/" directory 755 (world readable and
> executable) and it works!
>
> So the big question is: Am I crazy to expect PHP to work the same way on
> these different un*x variants? IS this a known problem, and is there seom
> other solution?
>

It looks like the getcwd call on the BSD systems returns the empty string
because it cannot read the parent directory. On linux getcwd uses the proc
filesystem to get this info when it cannot read the dir. Since the BSDs
(by default) don't have that they fail.

However, PHP should report an error when the PHP getcwd() fails due to
access restrictions. I shall report this as a bug.

A workaround to this, still allowing the scripts to be portable throught
the filesystem (i.e. no hard coded full paths is below):

<?
$scriptDir = dirname(getenv("DOCUMENT_ROOT").getenv("SCRIPT_NAME"));
include_once("$scriptDir/subdir/standard.inc");

...

?>

Include ALL files with the $scriptDir first and you are set. I think this
would be a good general practice to avoid this problem on any system where
it might occur.


--
Joe Laffey              |  Want to convert subnet masks between different
LAFFEY Computer Imaging |  notations, or figure the number of IPs in a block?
St. Louis, MO           |  Whatmask-It's FREE - www.laffeycomputer.com/wm.html
------------------------------------------------------------------------------

-- 
PHP Install Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to