mod_perl - separate PERL interpreter for each LocationMatch

mod_perl - separate PERL interpreter for each LocationMatch

am 12.09.2011 09:22:57 von utham hoode

--_32c6384b-d9ee-4ae9-9752-cda1911e339e_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable


Hi All=2C I have written a mod_perl proxy server which redirects th=
e HTTP traffic to a webserver. I have pasted the snippet below. In =
the apache worker thread=2C is enable. In the httpd.conf two > are configured http://ipaddress/path1/http://ipaddress/path2/ After start=
ing the http server if i open any URL from the browser=2C same =93TEST_VAR=
=94 is being printedfor both the URLs. If I call path1 first=2C then for bo=
th the URLs 100 is printed.If I call path2 first=2C then for both the URLs =
200 is printed.(that is its taking the first called Path=2C after httpd is =
started) #----------------------------Startup.pl --------------------------=
------------------##startup.pl use lib qw(/home/test1/libs)=3B 1=3B #------=
--------------------------- #---------------------------- httpd.conf-------=
--------------------------------------# # httpd.conf PerlRequire /home/tes=
t1/startup.pl #http://ipaddress/path1/ SetEnvIf =
Request_URI "/" TEST_VAR=3D100 SetHandler perl-script PerlResponseH=
andler Module::Test
#http://ipaddress/path2/ /path2/> SetEnvIf Request_URI "/" TEST_VAR=3D200 SetHandler perl-sc=
ript PerlResponseHandler Module::Test
#----------------=
------------------------------------------------------------ ---# #--------=
-------------------- Test.pm ---------------------------------------------#=
# Test.pm package Module::Test=3B use strict=3B use Apache2::Const qw(:met=
hods :http :common)=3Buse Apache2::Log ()=3Buse Apache2::URI ()=3B my $par=
am =3D env_variable()=3B sub handler{ Apache2::ServerRec::warn($param)=
=3B print "Value".$param=3B return Apache2::Const::OK=3B} sub env_vari=
able{ # Configuration loading from a file during startup my $en=
dpointURL =3D $ENV{'TEST_VAR'}=3B return $endpointURL=3B} 1=3B #-----=
------------------------------------------------------------ ---------------=
But I tried with option and it is working fine as PerlOptio=
ns +Parent is present.But since the port numbers are different firefox will=
now allow simulataneous access toboth URL from same webpage. #http://ipad=
dress:8080/path1/ SetEnvIf Request_URI "/" TEST_VAR=
=3D100 PerlRequire /home/test1/startup.pl PerlOptions +Parent ocationMatch /path2/> SetHandler perl-script PerlResponse=
Handler Module::Test
#http://ipaddress:=
8085/path2/ SetEnvIf Request_URI "/" TEST_VAR=3D200 =
PerlRequire /home/test1/startup.pl PerlOptions +Parent Match /path2/> SetHandler perl-script PerlResponseHandler=
Module::Test
Please help me with this=
=2C Thanks in advance.Regards=2Cuttam =

--_32c6384b-d9ee-4ae9-9752-cda1911e339e_
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable






le-span" face=3D"Tahoma" size=3D"2">Hi All=2C

al"> =3B &n=
bsp=3B  =3B

-span" face=3D"Tahoma" size=3D"2"> =3B  =3B I have written a mod_pe=
rl proxy server which redirects the HTTP traffic to a webserver.

=

e=3D"2"> =3B  =3B I have pasted the snippet below.  =3B<=
/p>

size=3D"2"> =3B  =3B In the apache worker thread=2C is enable. In t=
he httpd.conf two <=3BLocationMatch>=3B are configured

ss=3D"MsoNormal"> "> =3B

" face=3D"Tahoma" size=3D"2">http://ipaddress/path1/

MsoNormal">http=
://ipaddress/path2/

tyle-span" face=3D"Tahoma" size=3D"2"> =3B

mal">After star=
ting the http server if i open any URL from the browser=2C same =93TEST_VAR=
=94 is being printed

style-span" face=3D"Tahoma" size=3D"2">for both the URLs.

s=3D"MsoNormal"> > =3B

face=3D"Tahoma" size=3D"2">If I call path1 first=2C then for both the URLs=
100 is printed.

e-span" face=3D"Tahoma" size=3D"2">If I call path2 first=2C then for both t=
he URLs 200 is printed.

le-style-span" face=3D"Tahoma" size=3D"2">(that is its taking the first cal=
led Path=2C after httpd is started)

class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

class=3D"MsoNormal"> =3D"2">#----------------------------Startup.pl ----------------------------=
----------------#

le-span" face=3D"Tahoma" size=3D"2">#startup.pl

rmal"> =3B<=
/font>

ahoma" size=3D"2">use lib qw(/home/test1/libs)=3B

Normal"> =
=3B

=3D"Tahoma" size=3D"2">1=3B

"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

=3D"MsoNormal">=
#---------------------------------

lass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

class=3D"MsoNormal"> =3D"2">#---------------------------- httpd.conf----------------------------=
-----------------#

yle-span" face=3D"Tahoma" size=3D"2"> =3B

al"> =3B ont>

oma" size=3D"2"># httpd.conf

=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

s=3D"MsoNormal"> >PerlRequire /home/test1/startup.pl

class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

class=3D"MsoNormal"> =3D"2">#http://ipaddress/path1/

s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"><=3BLocationMatch /path=
1/>=3B

face=3D"Tahoma" size=3D"2"> =3B  =3B  =3BSetEnvIf Request_URI "=
/" TEST_VAR=3D100

le-span" face=3D"Tahoma" size=3D"2"> =3B  =3B  =3BSetHandler pe=
rl-script

face=3D"Tahoma" size=3D"2"> =3B  =3B  =3BPerlResponseHandler M=
odule::Test

n" face=3D"Tahoma" size=3D"2"><=3B/LocationMatch>=3B

=3D"MsoNormal">=
 =3B

face=3D"Tahoma" size=3D"2">#http://ipaddress/path2/

soNormal"><=
=3BLocationMatch /path2/>=3B

=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B  =3B=
SetEnvIf Request_URI "/" TEST_VAR=3D200

ont class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B=
 =3BSetHandler perl-script

s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B  =
=3BPerlResponseHandler Module::Test

class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"><=3B/LocationMatch&=
gt=3B

e=3D"Tahoma" size=3D"2"> =3B

ss=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">#-----------------------=
--------------------------------------------------------#

s=3D"MsoNormal"> > =3B

face=3D"Tahoma" size=3D"2"> =3B

class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">#-------------------=
--------- Test.pm ---------------------------------------------#

=

e=3D"2"> =3B

e-span" face=3D"Tahoma" size=3D"2"># Test.pm

l"> =3B nt>

ma" size=3D"2">package Module::Test=3B

nt class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B >

ze=3D"2">use strict=3B

e-style-span" face=3D"Tahoma" size=3D"2"> =3B

Normal">use Apa=
che2::Const qw(:methods :http :common)=3B

=
use Apache2::Lo=
g ()=3B

ace=3D"Tahoma" size=3D"2">use Apache2::URI ()=3B

ormal"> =3B=

Tahoma" size=3D"2"> =3B

"Apple-style-span" face=3D"Tahoma" size=3D"2">my $param =3D env_variable()=
=3B

=3D"Tahoma" size=3D"2"> =3B

s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">sub handler

class=3D"MsoNormal"> =3D"2">{

face=3D"Tahoma" size=3D"2"> =3B

class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3BApac=
he2::ServerRec::warn($param)=3B

s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3Bprint "V=
alue".$param=3B

-span" face=3D"Tahoma" size=3D"2"> =3B  =3Breturn Apache2::Const::O=
K=3B

=3D"Tahoma" size=3D"2">}

ple-style-span" face=3D"Tahoma" size=3D"2"> =3B

soNormal"> =
=3B

=3D"Tahoma" size=3D"2">sub env_variable

ont class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">{

ass=3D"MsoNormal"> 2"> =3B

n" face=3D"Tahoma" size=3D"2"> =3B  =3B  =3B # Configuration lo=
ading from a file during startup

ss=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

ass=3D"MsoNormal"> 2"> =3B  =3B  =3B my $endpointURL =3D $ENV{'TEST_VAR'}=3B >

" size=3D"2"> =3B

-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B  =3B return $=
endpointURL=3B

span" face=3D"Tahoma" size=3D"2">}

lass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

class=3D"MsoNormal"> =3D"2">1=3B

n" face=3D"Tahoma" size=3D"2"> =3B

nt class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">#-----------------=
------------------------------------------------------------ ---

<=
p class=3D"MsoNormal"> =3D"2"> =3B

-span" face=3D"Tahoma" size=3D"2"> =3B

>But I tried wi=
th <=3BVirtualHost>=3B option and it is working fine as PerlOptions +Pa=
rent is present.

e-span" face=3D"Tahoma" size=3D"2">But since the port numbers are different=
firefox will now allow simulataneous access to

rmal">both URL =
from same webpage.

yle-span" face=3D"Tahoma" size=3D"2"> =3B

al"> =3B ont>

oma" size=3D"2">#http://ipaddress:8080/path1/

al"><=3BVirtu=
alHost *:8080>=3B

tyle-span" face=3D"Tahoma" size=3D"2"> =3B  =3B SetEnvIf Request_UR=
I "/" TEST_VAR=3D100

style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B PerlRequire /home/=
test1/startup.pl

e-span" face=3D"Tahoma" size=3D"2"> =3B

"> =3B &nbs=
p=3B PerlOptions +Parent

ple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B  =3B<=3B=
LocationMatch /path2/>=3B

"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B  =3B &n=
bsp=3B  =3B SetHandler perl-script

nt class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B =
 =3B  =3B  =3B PerlResponseHandler Module::Test

ass=3D"MsoNormal"> 2"> =3B  =3B  =3B<=3B/LocationMatch>=3B

=3D"MsoNormal">=
<=3B/VirtualHost>=3B

ple-style-span" face=3D"Tahoma" size=3D"2"> =3B

soNormal"> =
=3B

=3D"Tahoma" size=3D"2">#http://ipaddress:8085/path2/

MsoNormal"><=
=3BVirtualHost *:8085>=3B

"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B SetEnvIf Re=
quest_URI "/" TEST_VAR=3D200

=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B PerlRequ=
ire /home/test1/startup.pl

Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

"MsoNormal">&nb=
sp=3B  =3B PerlOptions +Parent

lass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B &nbs=
p=3B<=3BLocationMatch /path2/>=3B

t class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B  =3B &=
nbsp=3B  =3B  =3B SetHandler perl-script

ormal"> =3B=
 =3B  =3B  =3B  =3B PerlResponseHandler Module::Test >

" size=3D"2"> =3B  =3B  =3B<=3B/LocationMatch>=3B >

ze=3D"2"><=3B/VirtualHost>=3B

ass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

lass=3D"MsoNormal"> "2">Please help me with this=2C Thanks in advance.

oNormal">Regard=
s=2C

=3D"Tahoma" size=3D"2">uttam

=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"> =3B

iv>

=

--_32c6384b-d9ee-4ae9-9752-cda1911e339e_--

Re: mod_perl - separate PERL interpreter for each LocationMatch

am 12.09.2011 10:18:59 von torsten.foertsch

On Monday, 12 September 2011 09:22:57 utham hoode wrote:
> Hi All, I have written a mod_perl proxy server which redirects
> the HTTP traffic to a webserver. I have pasted the snippet below.=20
> 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 â€=9CTEST_VAR=E2=
€ is
> being printedfor 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.(that is its taking the first called Path, after httpd
> is started) #----------------------------Startup.pl
> --------------------------------------------##startup.pl use lib
> qw(/home/test1/libs); 1; #---------------------------------
> #----------------------------
> httpd.conf---------------------------------------------# #
> httpd.conf PerlRequire /home/test1/startup.pl
> #http://ipaddress/path1/ SetEnvIf
> Request_URI "/" TEST_VAR=3D100 SetHandler perl-script =20
> PerlResponseHandler Module::Test

> #http://ipaddress/path2/ SetEnvIf
> Request_URI "/" TEST_VAR=3D200 SetHandler perl-script =20
> PerlResponseHandler Module::Test

> #----------------------------------------------------------- ---------
> -----------# #---------------------------- Test.pm
> ---------------------------------------------# # Test.pm package
> Module::Test; use strict; use Apache2::Const qw(:methods :http
> :common);use Apache2::Log ();use Apache2::URI (); my $param =3D
> env_variable(); sub handler{ Apache2::ServerRec::warn($param); =20
> print "Value".$param; return Apache2::Const::OK;} sub
> env_variable{ # Configuration loading from a file during
> startup my $endpointURL =3D $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 toboth URL from
> same webpage. #http://ipaddress:8080/path1/ =20
> SetEnvIf Request_URI "/" TEST_VAR=3D100 PerlRequire
> /home/test1/startup.pl PerlOptions +Parent > /path2/> SetHandler perl-script PerlResponseHandler
> Module::Test
=20
> #http://ipaddress:8085/path2/ SetEnvIf
> Request_URI "/" TEST_VAR=3D200 PerlRequire /home/test1/startup.pl =20
> PerlOptions +Parent SetHandler
> perl-script PerlResponseHandler Module::Test =20
>
Please help me with this, Thanks in
> advance.Regards,uttam

Could you please resend the mail with proper line breaks? Otherwise, it's=20
indecipherable, at least for me.

Torsten Förtsch

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

Like fantasy? http://kabatinte.net

RE: mod_perl - separate PERL interpreter for each LocationMatch

am 12.09.2011 11:04:35 von utham hoode

Hi All=2C

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.

#startup.pl
use lib qw(/home/test1/libs)=3B
1=3B

#---------------------------------

# httpd.conf
PerlRequire /home/test1/startup.pl
#http://ipaddress/path1/

SetEnvIf Request_URI "/" TEST_VAR=3D100
SetHandler perl-script
PerlResponseHandler Module::Test

#http://ipaddress/path2/

SetEnvIf Request_URI "/" TEST_VAR=3D200
SetHandler perl-script
PerlResponseHandler Module::Test


#Test.pm
#----------------------------------------------------------- ---------
package Module::Test=3B
use strict=3B
use Apache2::Const qw(:methods :http :common)=3B
use Apache2::Log ()=3B
use Apache2::URI ()=3B

my $param =3D env_variable()=3B
sub handler
{
Apache2::ServerRec::warn($param)=3B
print "Value".$param=3B
return Apache2::Const::OK=3B
}

sub env_variable
{
# Configuration loading from a file during startup
my $endpointURL =3D $ENV{'TEST_VAR'}=3B
return $endpointURL=3B
}
1=3B
#----------------------------------------------------------- ---------------=
------

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 simulataneo=
us
access to
both URL from same webpage.

#http://ipaddress:8080/path1/

SetEnvIf Request_URI "/" TEST_VAR=3D100
PerlRequire /home/test1/startup.pl
PerlOptions +Parent

SetHandler perl-script
PerlResponseHandler Module::Test



#http://ipaddress:8085/path2/

SetEnvIf Request_URI "/" TEST_VAR=3D200
PerlRequire /home/test1/startup.pl
PerlOptions +Parent

SetHandler perl-script
PerlResponseHandler Module::Test



Regards=2C
uttam


----------------------------------------
> From: torsten.foertsch@gmx.net
> To: modperl@perl.apache.org
> Subject: Re: mod_perl - separate PERL interpreter for each LocationMatch
> Date: Mon=2C 12 Sep 2011 10:18:59 +0200
> CC: uttamhoode@live.com
>
> On Monday=2C 12 September 2011 09:22:57 utham hoode wrote:
> > Hi All=2C I have written a mod_perl proxy server which redirects
> > the HTTP traffic to a webserver. I have pasted the snippet below.
> > In the apache worker thread=2C 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=2C same =93TEST_VAR=94 i=
s
> > being printedfor both the URLs. If I call path1 first=2C then for both
> > the URLs 100 is printed.If I call path2 first=2C then for both the URLs
> > 200 is printed.(that is its taking the first called Path=2C after httpd
> > is started) #----------------------------Startup.pl
> > --------------------------------------------##startup.pl use lib
> > qw(/home/test1/libs)=3B 1=3B #---------------------------------
> > #----------------------------
> > httpd.conf---------------------------------------------# #
> > httpd.conf PerlRequire /home/test1/startup.pl
> > #http://ipaddress/path1/ SetEnvIf
> > Request_URI "/" TEST_VAR=3D100 SetHandler perl-script
> > PerlResponseHandler Module::Test
> > #http://ipaddress/path2/ SetEnvIf
> > Request_URI "/" TEST_VAR=3D200 SetHandler perl-script
> > PerlResponseHandler Module::Test
> > #----------------------------------------------------------- ---------
> > -----------# #---------------------------- Test.pm
> > ---------------------------------------------# # Test.pm package
> > Module::Test=3B use strict=3B use Apache2::Const qw(:methods :http
> > :common)=3Buse Apache2::Log ()=3Buse Apache2::URI ()=3B my $param =3D
> > env_variable()=3B sub handler{ Apache2::ServerRec::warn($param)=3B
> > print "Value".$param=3B return Apache2::Const::OK=3B} sub
> > env_variable{ # Configuration loading from a file during
> > startup my $endpointURL =3D $ENV{'TEST_VAR'}=3B return
> > $endpointURL=3B} 1=3B
> > #----------------------------------------------------------- ---------
> > ------------ 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 toboth URL from
> > same webpage. #http://ipaddress:8080/path1/
> > SetEnvIf Request_URI "/" TEST_VAR=3D100 PerlRequire
> > /home/test1/startup.pl PerlOptions +Parent > /path2/> SetHandler perl-s=
cript PerlResponseHandler
> > Module::Test
> > #http://ipaddress:8085/path2/ SetEnvIf
> > Request_URI "/" TEST_VAR=3D200 PerlRequire /home/test1/startup.pl
> > PerlOptions +Parent SetHandler
> > perl-script PerlResponseHandler Module::Test
> > Please help me with this=2C Thanks in
> > advance.Regards=2Cuttam
>
> Could you please resend the mail with proper line breaks? Otherwise=2C it=
's
> indecipherable=2C at least for me.
>
> Torsten Förtsch
>
> --
> Need professional modperl support? Hire me! (http://foertsch.name)
>
> Like fantasy? http://kabatinte.net =

Re: mod_perl - separate PERL interpreter for each LocationMatch

am 12.09.2011 11:52:57 von torsten.foertsch

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=20
"modperl proxy server that redirects" is quite ambiguous:

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

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

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

=2D perhaps there are a few more possible meanings

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

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

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

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

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

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

> sub handler
> {
> Apache2::ServerRec::warn($param);
> print "Value".$param;
> return Apache2::Const::OK;
> }
>=20
> sub env_variable
> {
> # Configuration loading from a file during startup
> my $endpointURL =3D $ENV{'TEST_VAR'};
> return $endpointURL;
> }
> 1;
> #----------------------------------------------------------- ----------
> -----------
>=20
> 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.
>=20
> #http://ipaddress:8080/path1/
>=20
> SetEnvIf Request_URI "/" TEST_VAR=3D100
> PerlRequire /home/test1/startup.pl
> PerlOptions +Parent
>=20
> SetHandler perl-script
> PerlResponseHandler Module::Test
>=20
>=20
>=20
> #http://ipaddress:8085/path2/
>=20
> SetEnvIf Request_URI "/" TEST_VAR=3D200
> PerlRequire /home/test1/startup.pl
> PerlOptions +Parent
>=20
> SetHandler perl-script
> PerlResponseHandler Module::Test

+Parent is a VHost level option like:


PerlOptions +Parent
...


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


PerlSwitches ...
PerlRequire ...
PerlModule ...



PerlSwitches ...
PerlRequire ...
PerlModule ...



PerlUseInterpreter MyInterpreter


Torsten Förtsch

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

Like fantasy? http://kabatinte.net

RE: mod_perl - separate PERL interpreter for each LocationMatch

am 12.09.2011 13:03:30 von utham hoode

----------------------------------------
> From: torsten.foertsch@gmx.net
> To: modperl@perl.apache.org
> Subject: Re: mod_perl - separate PERL interpreter for each LocationMatch
> Date: Mon=2C 12 Sep 2011 11:52:57 +0200
> CC: uttamhoode@live.com
>
> On Monday=2C 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:

Thanks for the quick response.
Sorry for not providing all the details. Actual proxy program is working fi=
ne withsingle . I wrote Test.pm just to demonstrate the issu=
e.

>
> - a modperl handler that works in the response phase=2C mangles the reque=
st
> 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=2C 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 blocks that are applicable.
>
> So=2C you can set a certain environment variable for one request to value=
1
> and for another to value2. But you have to have a distinguishing mark.
>
> > #startup.pl
> > use lib qw(/home/test1/libs)=3B
> > 1=3B
> >
> > #---------------------------------
> >
> > # httpd.conf
> > PerlRequire /home/test1/startup.pl
> > #http://ipaddress/path1/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D100
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
> >
> > #http://ipaddress/path2/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D200
> > 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.

I tried this but did not work.
SetEnvIf Request_URI "/path1/" TEST_VAR=3D100
and=A0
SetEnvIf Request_URI "/path2/" TEST_VAR=3D200


>
> >
> > #Test.pm
> > #----------------------------------------------------------- ---------
> > package Module::Test=3B
> > use strict=3B
> > use Apache2::Const qw(:methods :http :common)=3B
> > use Apache2::Log ()=3B
> > use Apache2::URI ()=3B
> >
> > my $param =3D env_variable()=3B
>
> 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.


Here is the problem. Both path1 and path2 are sharing same global variable =
$param.Is there any way to avoid that?. Because In the actual proxy program=
I am reading aconfiguration file and storing it in a global variable. For =
path1 and path2=A0configuration file is different. I can place the variable=
inside sub handler {}so that for =A0each request program loads the configu=
ration file.I think this will reduce the performance.

>
> > sub handler
> > {
> > Apache2::ServerRec::warn($param)=3B
> > print "Value".$param=3B
> > return Apache2::Const::OK=3B
> > }
> >
> > sub env_variable
> > {
> > # Configuration loading from a file during startup
> > my $endpointURL =3D $ENV{'TEST_VAR'}=3B
> > return $endpointURL=3B
> > }
> > 1=3B
> > #----------------------------------------------------------- ----------
> > -----------
> >
> > 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=3D100
> > PerlRequire /home/test1/startup.pl
> > PerlOptions +Parent
> >
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
> >
> >
> >
> > #http://ipaddress:8085/path2/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D200
> > PerlRequire /home/test1/startup.pl
> > PerlOptions +Parent
> >
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
>
> +Parent is a VHost level option like:
>
>
> PerlOptions +Parent
> ...
>

>
> 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:
=A0   I wish below feature is supported.

>
>
> PerlSwitches ...
> PerlRequire ...
> PerlModule ...
>

>
>
> PerlSwitches ...
> PerlRequire ...
> PerlModule ...
>

>
>
> PerlUseInterpreter MyInterpreter
>

>
> Torsten Förtsch
>
> --
> Need professional modperl support? Hire me! (http://foertsch.name)
>
> Like fantasy? http://kabatinte.net
=

Re: mod_perl - separate PERL interpreter for each LocationMatch

am 12.09.2011 13:36:36 von torsten.foertsch

On Monday, 12 September 2011 13:03:30 utham hoode wrote:
> Here is the problem. Both path1 and path2 are sharing same global
> variable $param.Is there any way to avoid that?. Because In the
> actual proxy program I am reading aconfiguration file and storing it
> in a global variable. For path1 and path2 configuration file is
> different. I can place the variable inside sub handler {}so that for
> each request program loads the configuration file.I think this will
> reduce the performance.

how about

=3Dhttpd.conf===============3D=3 D=====
==================== =3D

SetEnv CFG /path/to/config1.conf



SetEnv CFG /path/to/config2.conf

==================== =====3D=
==================== =====3D=
==

=3Dthe handler=================3D=3 D===
====================
my %config;

sub handler {
my ($r)=3D@_;

my $cfg=3D$r->subprocess_env->{CFG} or
die "No config file configured for ".$r->uri;
=20
$cfg=3D($config{$cfg}||=3Dread_cfg $cfg);
...
}
==================== =====3D=
==================== =====3D=
==

Thus, the global %config is used as a cache for the configurations of the=20
various URIs. The actual file is read only on the first request.

All the configurations can even be pre-populated at startup time.

Note however, that since the config is read only once it can be changed=20
only by starting up a new interpreter. If that's a problem you can=20
monitor file modification times for example. If I were you I'd use an=20
MMapDB object.

Torsten Förtsch

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

Like fantasy? http://kabatinte.net