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 of
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 per
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"
directive.
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 <ben.rub...@gmail.com
<mailto:ben.rub...@gmail.com>> 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 copy
        on write memory (ie any change will only affect the process that 
changed it.)

        https://perl.apache.org/docs/2.0/user/handlers/server.html#Startup_File
        
<https://perl.apache.org/docs/2.0/user/handlers/server.html#Startup_File>

        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 above).
            I need the var to be set only one time to a constant random value, 
then to be
            read by the different processes.
            I then also thought about an environment variable set when Apache 
starts, and
            then given to Perl using "PerlSetVar var ${VAR}".
            But 1. var value would be disclosed into Apache env which I want to 
avoid, 2.
            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:*/
/j...@lariat.co <mailto:j...@lariat.co>/
/
*Customer Service:*/
877.268.6667
supp...@lariat.co <mailto:supp...@lariat.co>

Reply via email to