You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Nishikant Kapoor <nk...@webrachna.com> on 2011/11/30 04:29:14 UTC

Running multiple copies of same site in ModPerl

Hello List,

I have been running a ModPerl site fine with following configuration. 
The problem started when I made a complete copy of the original site and 
tried to run the two in the same environment. For some reason, calling 
up the ORIG site (http://127.0.0.1/ORIG/) now calls the COPY site at 
http://127.0.0.1/COPY/. None of the changes made in ORIG::MODS::base.pm 
are getting picked up even after restarting the apache server. However, 
changes to COPY::MODS::base.pm are showing up  fine.

Would appreciate any help. Here is what I have in the config:

/etc/httpd/conf/httpd.conf:
---------------------------
PerlRequire /var/www/perl/startup.pl
<Location /ORIG>
  SetHandler perl-script
  PerlResponseHandler ORIG::MODS::base
</Location>

<Location /COPY>
  SetHandler perl-script
  PerlResponseHandler COPY::MODS::base
</Location>

/var/www/perl/startup.pl:
-------------------------
use lib qw(/var/www/perl);
use lib qw(/var/www/perl/ORIG);
use lib qw(/var/www/perl/COPY);
1;

Apache/2.2.14 (Mandriva Linux/PREFORK-1mdv2010.0)
apache-mod_perl-2.0.4-11mdv2010.0
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Thanks,
Nishi


Re: Running multiple copies of same site in ModPerl

Posted by gAzZaLi <ba...@bac2bac.com>.
Hello,

What you're doing is not recommended as you run into namespace issues.

Perl caches files and modules that were loaded in %INC, so if you have 
files and modules with the same name, only one of them gets loaded. 
Possibly, as an exercise, if you switch the order of the ORIG and COPY 
lines in your startup.pl, you'll see the changes you've made in ORIG and 
not the changes in COPY.

I've made the assumption here that your site is more than just the one 
base.pm file and both base.pm packages use other packages with the same 
names.

Suppose your

ORIG::mods::base.pm has "use mods::somepackage"
and
COPY::mods::base.pm has "use mods::somepackage",

with the startup.pl file, Perl will load only the 
.../perl/COPY/mods/somepackage.pm file.

If however your site is just the base.pm file, and the package 
declaration is as you've written, my answer is off.

Good luck.

g.

On 11/29/2011 7:29 PM, Nishikant Kapoor wrote:
> Hello List,
>
> I have been running a ModPerl site fine with following configuration.
> The problem started when I made a complete copy of the original site and
> tried to run the two in the same environment. For some reason, calling
> up the ORIG site (http://127.0.0.1/ORIG/) now calls the COPY site at
> http://127.0.0.1/COPY/. None of the changes made in ORIG::MODS::base.pm
> are getting picked up even after restarting the apache server. However,
> changes to COPY::MODS::base.pm are showing up fine.
>
> Would appreciate any help. Here is what I have in the config:
>
> /etc/httpd/conf/httpd.conf:
> ---------------------------
> PerlRequire /var/www/perl/startup.pl
> <Location /ORIG>
> SetHandler perl-script
> PerlResponseHandler ORIG::MODS::base
> </Location>
>
> <Location /COPY>
> SetHandler perl-script
> PerlResponseHandler COPY::MODS::base
> </Location>
>
> /var/www/perl/startup.pl:
> -------------------------
> use lib qw(/var/www/perl);
> use lib qw(/var/www/perl/ORIG);
> use lib qw(/var/www/perl/COPY);
> 1;
>
> Apache/2.2.14 (Mandriva Linux/PREFORK-1mdv2010.0)
> apache-mod_perl-2.0.4-11mdv2010.0
> This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
>
> Thanks,
> Nishi
>
>
>


Re: Running multiple copies of same site in ModPerl

Posted by Rolf Schaufelberger <rs...@plusw.de>.
Am 30.11.2011 um 15:02 schrieb Michael Peters:

> On 11/29/2011 10:29 PM, Nishikant Kapoor wrote:
> 
>> I have been running a ModPerl site fine with following configuration.
>> The problem started when I made a complete copy of the original site and
>> tried to run the two in the same environment. For some reason, calling
>> up the ORIG site (http://127.0.0.1/ORIG/) now calls the COPY site at
>> http://127.0.0.1/COPY/. None of the changes made in ORIG::MODS::base.pm
>> are getting picked up even after restarting the apache server. However,
>> changes to COPY::MODS::base.pm are showing up fine.
> 
> The problem is that mod_perl uses the same Perl interpreter for everything (by default) and that interpreter is persistent. I'm guessing that your "package" declaration in ORIG::MODS::base.pm and COPY::MODS::base.pm are the same. Perl won't load 2 packages of the same name. The usual solutions are:
> 
> 1) rename your modules so that they don't have the same package names.
> 
> 2) run multiple separate apaches on the same physical server (not as hard as it seems to most people and pretty easy to do if you're running a proxy in front. And you really should be running a proxy in front).
> 
> 3) Try to have multiple Perl interpreters using a different Apache MPM. I haven't seen anyone give a definitive guide to how to do this (although I could have missed something) and results seem to be mixed.
> 
> I prefer #2 and use it constantly. It also makes it really easy to have separate dev environments each using their own code.
> 

You could do that too with the "+parent" option, see mod_perl docs. So you don't need another apache instance (but you need a lot of RAM ).
This creates an own interpreter. But I'm not sure if  it can be applied  on a <Location> level or at least on <VirtualHost>


Rolf Schaufelberger








Re: Running multiple copies of same site in ModPerl

Posted by gAzZaLi <ba...@bac2bac.com>.
My point about switching the lines in startup.pl was to give you a 
better understanding of what was going on. It was not intended as a fix.

Looks like you've got your base.pm package declaration right. But for 
your sites to work as intended, you've got to do that for all the 
modules in /ORIG/mods and /COPY/mods, not just the response handler. And 
then you have to change all the code that once refered to 
"mods::something" to "ORIG::mods::something" and same for COPY.
But please do NOT do this as it's a bad idea and leads to premature aging.

If you're interested further in the namespace issue, check this out from 
the Practial mod_perl book:
http://modperlbook.org/html/6-3-Namespace-Issues.html

As for a good solution, which I forgot to mention but others have, go 
with #2 -- setting up separate instances of Apache on the same physical 
server. The Practical mod_perl book has information on multiple server 
setups too and good points to consider when running separate dev, 
staging and production servers.


On 11/30/2011 10:15 AM, Nishikant Kapoor wrote:
> Michael Peters wrote:
>> On 11/29/2011 10:29 PM, Nishikant Kapoor wrote:
>>
>>> I have been running a ModPerl site fine with following configuration.
>>> The problem started when I made a complete copy of the original site and
>>> tried to run the two in the same environment. For some reason, calling
>>> up the ORIG site (http://127.0.0.1/ORIG/) now calls the COPY site at
>>> http://127.0.0.1/COPY/. None of the changes made in ORIG::MODS::base.pm
>>> are getting picked up even after restarting the apache server. However,
>>> changes to COPY::MODS::base.pm are showing up fine.
>>
>> The problem is that mod_perl uses the same Perl interpreter for
>> everything (by default) and that interpreter is persistent. I'm
>> guessing that your "package" declaration in ORIG::MODS::base.pm and
>> COPY::MODS::base.pm are the same. Perl won't load 2 packages of the
>> same name. The usual solutions are:
> I thought about that too, and so I did change the "package" declaration
> in ORIG::MODS::base.pm and COPY::MODS::base.pm but calling up
> http://127.0.0.1/ORIG/ still calls http://127.0.0.1/COPY/. Here is what
> each base.pm has:
>
> /var/www/perl/COPY/MODS/base.pm:
> package COPY::MODS::base;
>
> /var/www/perl/ORIG/MODS/base.pm:
> package ORIG::MODS::base;
>
> And, as gAzZaLi suggested, I also tried switching the order of the ORIG
> and COPY lines in startup.pl, and I could see the changes made in ORIG
> but not the changes in COPY. So, COPY indeed is overriding ORIG.
>
> As for the #2 mentioned below, are there any pointers that you could
> refer to?
>
> Thanks,
> Nishi
>>
>> 1) rename your modules so that they don't have the same package names.
>>
>> 2) run multiple separate apaches on the same physical server (not as
>> hard as it seems to most people and pretty easy to do if you're
>> running a proxy in front. And you really should be running a proxy in
>> front).
>>
>> 3) Try to have multiple Perl interpreters using a different Apache
>> MPM. I haven't seen anyone give a definitive guide to how to do this
>> (although I could have missed something) and results seem to be mixed.
>>
>> I prefer #2 and use it constantly. It also makes it really easy to
>> have separate dev environments each using their own code.
>>
>
>
>


Re: Running multiple copies of same site in ModPerl

Posted by Nishikant Kapoor <nk...@webrachna.com>.
Michael Peters wrote:
> On 11/29/2011 10:29 PM, Nishikant Kapoor wrote:
>
>> I have been running a ModPerl site fine with following configuration.
>> The problem started when I made a complete copy of the original site and
>> tried to run the two in the same environment. For some reason, calling
>> up the ORIG site (http://127.0.0.1/ORIG/) now calls the COPY site at
>> http://127.0.0.1/COPY/. None of the changes made in ORIG::MODS::base.pm
>> are getting picked up even after restarting the apache server. However,
>> changes to COPY::MODS::base.pm are showing up fine.
>
> The problem is that mod_perl uses the same Perl interpreter for 
> everything (by default) and that interpreter is persistent. I'm 
> guessing that your "package" declaration in ORIG::MODS::base.pm and 
> COPY::MODS::base.pm are the same. Perl won't load 2 packages of the 
> same name. The usual solutions are:
I thought about that too, and so I did change the "package" declaration 
in ORIG::MODS::base.pm and COPY::MODS::base.pm but calling up 
http://127.0.0.1/ORIG/ still calls http://127.0.0.1/COPY/. Here is what 
each base.pm has:

/var/www/perl/COPY/MODS/base.pm:
package COPY::MODS::base;

/var/www/perl/ORIG/MODS/base.pm:
package ORIG::MODS::base;

And, as gAzZaLi suggested, I also tried switching the order of the ORIG 
and COPY lines in startup.pl, and I could see the changes made in ORIG 
but not the changes in COPY. So, COPY indeed is overriding ORIG.

As for the #2 mentioned below, are there any pointers that you could 
refer to?

Thanks,
Nishi
>
> 1) rename your modules so that they don't have the same package names.
>
> 2) run multiple separate apaches on the same physical server (not as 
> hard as it seems to most people and pretty easy to do if you're 
> running a proxy in front. And you really should be running a proxy in 
> front).
>
> 3) Try to have multiple Perl interpreters using a different Apache 
> MPM. I haven't seen anyone give a definitive guide to how to do this 
> (although I could have missed something) and results seem to be mixed.
>
> I prefer #2 and use it constantly. It also makes it really easy to 
> have separate dev environments each using their own code.
>


Re: Running multiple copies of same site in ModPerl

Posted by Michael Peters <mp...@plusthree.com>.
On 11/29/2011 10:29 PM, Nishikant Kapoor wrote:

> I have been running a ModPerl site fine with following configuration.
> The problem started when I made a complete copy of the original site and
> tried to run the two in the same environment. For some reason, calling
> up the ORIG site (http://127.0.0.1/ORIG/) now calls the COPY site at
> http://127.0.0.1/COPY/. None of the changes made in ORIG::MODS::base.pm
> are getting picked up even after restarting the apache server. However,
> changes to COPY::MODS::base.pm are showing up fine.

The problem is that mod_perl uses the same Perl interpreter for 
everything (by default) and that interpreter is persistent. I'm guessing 
that your "package" declaration in ORIG::MODS::base.pm and 
COPY::MODS::base.pm are the same. Perl won't load 2 packages of the same 
name. The usual solutions are:

1) rename your modules so that they don't have the same package names.

2) run multiple separate apaches on the same physical server (not as 
hard as it seems to most people and pretty easy to do if you're running 
a proxy in front. And you really should be running a proxy in front).

3) Try to have multiple Perl interpreters using a different Apache MPM. 
I haven't seen anyone give a definitive guide to how to do this 
(although I could have missed something) and results seem to be mixed.

I prefer #2 and use it constantly. It also makes it really easy to have 
separate dev environments each using their own code.

-- 
Michael Peters
Plus Three, LP