On Fri 15 Aug 2008, Berg, Eric wrote:
> This issue of the environment variables' not being passed to forked
> processes is turning into a fairly substantial problem for me.   We
> have a number of places in our code -- both the modules that are
> tightly controlled and fairly easy to manage, as well as a bunch of
> scripts and CGI's that use them -- that use system or backticks
> (sometimes via IPC::Run3) to get info from external tools.
>
> Does anybody know anything about this issue or about the code
> involved?  How difficult would it be to address this?  I took a look
> at the code in modperl_env.c as suggested in the docs, but I'm a Perl
> guy, not a C guy.  
>
> This is a deal killer for us.  

Let's have a look at the reason for this behavior first. It's always 
better to know what you are doing. Apache 2.x can use various MPMs. 
Some of them use threads instead of processes to achieve parallelism. 
Now, the environment is a process global resource. So, if those values 
are changed all threads are affected. This is surely no what you want.

Therefore there is a request specific data structure called 
subprocess_env where environment variables for CGI scripts are kept. If 
you use the Apache interface to spawn subprocesses 
(Apache2::SubProcess) you'll notice that variables set in 
subprocess_env appear as environment variables of the spawned process. 
Under mod_perl %ENV is tied to $r->subprocess_env.

If you are using the prefork MPM (as you probably do) you can still 
manipulate the environment without affecting other requests. But you 
have to use the C-level functions. There is a module called Env::C on 
CPAN that provides a perl interface to them.

Torsten

--
Need professional mod_perl support?
Just hire me: [EMAIL PROTECTED]

Reply via email to