perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier (tomcat)>
Subject Re: Shared var between processes
Date Fri, 20 Oct 2017 08:38:57 GMT
On 19.10.2017 22:02, John Dunlap wrote:
> To piggy back onto this question, what is the best way to do this such that the values
> the variables are different for every virtual host? In our model, all virtual hosts shared
> the same interpreter pool but we need to have different configuration variables on a
> virtualhost basis. Currently, we are using PerlSetVar for this purpose.

And that seems the right way to me.

As log as you remember that a VirtualHost is not really a "process". It is a 
"configuration block", which any Apache process/thread starting to handle a HTTP request 
will first "load", before it starts processing a request destined to that VirtualHost.
In that configuration block, somewhere there is the digested form of that
PerlSetVar name "value"
By (dynamically) retrieving this "value" by means of a
$value = $r->dir_config(name)
you are just retrieving (dynamically, now) the (fixed) "value" set (earlier) in that 
configuration directive, and assigning this value to the local variable $value.
After that, any change which you may make to $value, is purely local and never re-written

into the VirtualHost configuration block.
So the next HTTP request, even if it is for the same VirtualHost, will still see the 
original "value" that was set in the configuration file.

It is only when you want to modify this value at some point, and to "leak" this new value

to other HTTP requests, that things become a bit more complicated.

Schematically :
1) the HTTP request "arrives" at the Apache httpd main process
2) the httpd main process looks for (or starts) a child process or thread, to handle this

request, and hands it off to that child. The main httpd now goes back to listening 
forother requests.
3) the selected child parses the request, and (via the "Host:" header), determines to 
which VirtualHost this is addressed
4) the child loads the configuration of that particular VirtualHost
5) the child starts processing the HTTP request, in function of this now-loaded configuration
(and thus also only the PerlSetVar directives that are part of the configuration of /that/

VirtualHost; it never sees the directives of the other VirtuaHosts)

> On Thu, Oct 19, 2017 at 3:57 PM, Ben RUBSON <
> <>> wrote:
>     Nice, perfect, just tested, working perfectly !
>     Thank you very much Adam !
>     Ben
>     On 19 Oct 2017 18:39, Adam Prime wrote:
>         If it doesn't need to change then you should be able to set it in
>         PerlPostConfigRequire code, and it will then be available to all children in
>         on write memory (ie any change will only affect the process that changed it.)
>         <>
>         Adam
>         On 17-10-19 12:11 PM, Ben RUBSON wrote:
>             Hi,
>             I'm trying to share a var between the different processes of my prefork Apache.
>             I then tried the following idea :
>             $r->server()->dir_config('var','val');
>             Unfortunately, $r->server()->dir_config('var') is not shared among
the processes.
>             I would have thought config was stored at the very first Apache process (the
>             parent) level.
>             Other solution is IPC::Shareable (one more module to load :-/)
>             Any other solution ?
>             I would have been happy with an Apache-only way to do this (like I tried
>             I need the var to be set only one time to a constant random value, then to
>             read by the different processes.
>             I then also thought about an environment variable set when Apache starts,
>             then given to Perl using "PerlSetVar var ${VAR}".
>             But 1. var value would be disclosed into Apache env which I want to avoid,
>             PerlSetVar at every request is perhaps not really perfect in terms of performance.
>             Thank you very much for your help !
>             Ben
> --
> John Dunlap
> /CTO | Lariat/
> /
> /
> /*Direct:*/
> / <>/
> /
> *Customer Service:*/
> 877.268.6667
> <>

View raw message