Re: Current working directory and multi-threaded environments

From: Date: Wed, 15 Mar 2000 19:01:58 +0000
Subject: Re: Current working directory and multi-threaded environments
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-16851@lists.php.net to get a copy of this message
On Wed, 15 Mar 2000, Sascha Schumann wrote: > On Wed, Mar 15, 2000 at 08:32:43PM +0200, Andi Gutmans wrote: > > Hi, > > > > I want to layout a way to fix the issue of the chdir()'s in PHP which > > prevents PHP from working properly in multi-threaded environments. > > > > The solution will probably include doing one getcwd() on startup and > > setting a per-request variable with its value. > > > > >From that point on we'll never use chdir() and getcwd() anymore but > > something like virtual_chdir() and virtual_getcwd() which will behave the > > same way but will not really change the current working directory but will > > adjust the per-request cwd string. > > Additionally to this, we need a function which converts a > relative path to an absolute path. Otherwise, every user of > the virtual_* functions will have to reinvent the wheel. Yes I also thought about this. We need a function like virtual_get_full_pathname(char *path_to_file) The fopen_wrapper functions will probably do with just the two I mentioned. The code only seems to rely on those and I personally don't see myself diving into fopen-wrappers.c and rewriting it. For two reasons: a) It pretty much does what we want. b) That code is crazy and I don't think I'd survive it. > > Alternatively, we could provide wrappers around system calls. > The wrappers would convert the arguments passed to them and > call the real system function. > > I don't like this particularly, because there are many 3rd > party library functions which we cannot cover all. > > What do you think? I also don't like this. The virtual_get_full_pathname function (we have to come up with a better name ) will be simple enough IMO for all PHP modules to use it (unless they'll want to use the fopen_wrapper). > > Of course, the file opening functions will be changed to use the new > > functions instead of the original ones and then we should have pretty > > decent virtual current working directories. > > > > Comments? Does anyone have a better solution or see problems with this > > one? > > > > BTW, any idea if Apache changes the current working directory per-request? > > I grepped through Apache 2.0 yesterday and there don't seem to > be any request-related getcwd()s or chdir()s. Well I hope 1.3.x doesn't either. This way we can just call getcwd() once in php_module_startup(). > > > 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 meant Apache. In any case, this change should be done globally including for non-threaded environments. It shouldn't be too complex and we should get as much testing for it as possible. There aren't too many chdir()'s and getcwd()'s in PHP. So I guess we would have the following functions (ignore the actual ugly names). I think their prototypes will be a bit different from the regular ones so that we can optimize usage. There will be a very small amount of code to change: char *virtual_getcwd(int *length) - Returns cwd and length virtual_chdir(char *path) - Changes global cwd string. char *virtual_get_full_pathname(char *filepath, int *length) - Returns full path and its length. How about that? I think the sooner we start on this one the better. Andi

« previous php.dev (#16851) next »