Re: mod_perl - separate PERL interpreter for each LocationMatch

Torsten Förtsch <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
On Monday, 12 September 2011 11:04:35 utham hoode wrote:
> I have written a mod_perl proxy server which redirects the HTTP
> traffic to a webserver.
> In the apache worker thread is enable. In the httpd.conf two
> are configured
> http://ipaddress/path1/
> http://ipaddress/path2/
> After starting the http server if i open any URL from the browser same
> TEST_VAR is being printed
> for both the URLs.
> If I call path1 first then for both the URLs 100 is printed.
> If I call path2 first then for both the URLs 200 is printed.

I am still a bit at a loss what you are trying to do here. The phrase 
"modperl proxy server that redirects" is quite ambiguous:

- a modperl handler that works in the response phase, mangles the request 
a bit before sending it to a backend server. On the way back the response 
from the backend is again a bit mangled perhaps and sent to the client

- on the other hand it may be a server that sends out HTTP redirects to 
point the browser to the correct server using HTTP 3xx codes.

- and thirdly it may be a piece of code working in a phase between 
maptostorage and fixup that modifies the request configuration to have it
handled by mod_proxy.

- perhaps there are a few more possible meanings

Generally, apache creates an individual configuration for each request. 
At first it looks up the virtual server config. Then it merges into that 
one all the <Location> <Directory> <Files> blocks that are applicable.

So, you can set a certain environment variable for one request to value1 
and for another to value2. But you have to have a distinguishing mark.

> #startup.pl
> use lib qw(/home/test1/libs);
> 1;
> 
> #---------------------------------
> 
> # httpd.conf
> PerlRequire /home/test1/startup.pl
> #http://ipaddress/path1/
> 
> SetEnvIf Request_URI "/" TEST_VAR=100
> SetHandler perl-script
> PerlResponseHandler Module::Test
> 
> #http://ipaddress/path2/
> 
> SetEnvIf Request_URI "/" TEST_VAR=200
> SetHandler perl-script
> PerlResponseHandler Module::Test

In the snippet above I do not see any such mark. You set TEST_VAR to 100 
and to 200 if the request URI is /. That does not make sense.

> 
> #Test.pm
> #--------------------------------------------------------------------
> package Module::Test;
> use strict;
> use Apache2::Const qw(:methods :http :common);
> use Apache2::Log ();
> use Apache2::URI ();
> 
> my $param = env_variable();

Here you use a global variable that is set only once for the lifetime of 
the interpreter when the module is compiled. $param is not set for each 
request.

> sub handler
> {
> Apache2::ServerRec::warn($param);
> print "Value".$param;
> return Apache2::Const::OK;
> }
> 
> sub env_variable
> {
> # Configuration loading from a file during startup
> my $endpointURL = $ENV{'TEST_VAR'};
> return $endpointURL;
> }
> 1;
> #---------------------------------------------------------------------
> -----------
> 
> But I tried with option and it is working fine as PerlOptions
> +Parent is present.
> But since the port numbers are different firefox will now allow
> simulataneous access to
> both URL from same webpage.
> 
> #http://ipaddress:8080/path1/
> 
> SetEnvIf Request_URI "/" TEST_VAR=100
> PerlRequire /home/test1/startup.pl
> PerlOptions +Parent
> 
> SetHandler perl-script
> PerlResponseHandler Module::Test
> 
> 
> 
> #http://ipaddress:8085/path2/
> 
> SetEnvIf Request_URI "/" TEST_VAR=200
> PerlRequire /home/test1/startup.pl
> PerlOptions +Parent
> 
> SetHandler perl-script
> PerlResponseHandler Module::Test

+Parent is a VHost level option like:

<VirtualHost ...>
  PerlOptions +Parent
  ...
</VirtualHost>

The virtual host then gets it's own perl interpreter. It has been 
requested a few times to make it possible to change the interpreter per 
request configuration but nobody has got around to do the work yet. 
Something along these lines would be good:

<PerlInterpreter MyInterpreter>
PerlSwitches ...
PerlRequire ...
PerlModule ...
</PerlInterpreter>

<PerlInterpreter OtherInterpreter>
PerlSwitches ...
PerlRequire ...
PerlModule ...
</PerlInterpreter>

<Location /...>
PerlUseInterpreter MyInterpreter
</Location>

Torsten Förtsch

-- 
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.