Re: Re: Current working directory and multi-threaded environments
| From: | Andi Gutmans | Date: | Wed, 15 Mar 2000 19:26:59 +0000 |
| Subject: | Re: Re: Current working directory and multi-threaded environments | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-16854@lists.php.net to get a copy of this message | ||
On Wed, 15 Mar 2000 rubys@us.ibm.com wrote:
>
>
> >> I'm not sure if I need to do the real getcwd() per-request or if doing
> it
> >> on PHP startup once is good enough.
> >
> >Why should a threaded web server change its per-process
> >work directory?
>
> I'm confused. getwd doesn't change the working directory, right?
No it doesn't. But we call chdir() in PHP which means it changes the
current working directory and thus, the result of getcwd()
What I want to do is create a virtual current directory environment where
the current directory will be just some string saved in a global variable.
The new virtual_getcwd() will return that string, the new virtual_chdir()
will modify that string to be the new current working directory. And as
Sascha mentioned, we should have a third function which expans a relative
path to a full path according to what the "virtual" current working
directory is set to.
The reason I asked about doing getcwd() per request was that I'm not sure
if Apache when it serves you a request actually changes the current
working directory. If it does, then we'd need to intialize the global
virtual current directory every request for Apache by calling the real
getcwd(). If it doesn't, doing it once on PHP startup could be done for
all web servers both multi-threaded and single-threaded.
>
> In any case, I agree with Sascha...if it is at all possible, please don't
> change the working directory. Here's an excerpt from sapi/servlet which is
> my attempt to limit the scope of the problem this causes for Java until a
> real solution is available:
>
> getcwd(cwd,MAXPATHLEN);
> file_handle.handle.fp = php_fopen_primary_script();
> chdir(cwd);
This is exactly the problem I want to solve. chdir() is evil in
multi-threaded environments and there shouldn't be any such calls in PHP.
The whole notion of current working directories should be abstracted.
Right now ISAPI and any other multi-threaded PHP support is broken!
Andi