You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Steve Wilder <st...@m8rix.net> on 2004/07/18 08:04:35 UTC

Apache virtulahosts sharing modules

  Hello, all.

  I'm using Apache 1.3.29 and  Embperl 1.3.6

I've got two Apache Virtualhosts: www.benwilder, and rhyme.benwilder.com

Both sites have a "test1.phtml" which looks like this:
----------------------------
[! use test1; !]

[+ test1::whereami() +]<br>
----------------------------

Both sites have a test1.pm file which sits in their Document Root

Live's test1.pm looks like this:
----------------------------
package test1;

sub whereami {
   return "live";
}
1;
----------------------------

Rhyme's test1.pm looks like this:
----------------------------
package test1;

sub whereami {
   return "rhyme";
}
1;
----------------------------

The problem is that if I reload one or the other enough times, it will 
begin using the other sites test1.pm!  I need each site to only use it's 
own test1.pm.

If I restart Apache, the problem goes away for a time, but will come 
back if I reload one or the other enough times.

BTW: In my httpd.conf, I set "PerlSetEnv PERL5LIB" in the VirtualHost 
directive to its own Document Root.

How do I lock each VirtualHost to it's own test1.pm module?

Thanks,

Steve Wilder




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Apache virtulahosts sharing modules

Posted by Gerald Richter <ri...@ecos.de>.
Hi,

you have only _one_ Perl interpreter under mod_perl, so it is the same for
both virtual host, so you cannot load two different modules, with the same
package name.

See perl.apache.org in the mod_perl guide for more informations about this
topic.

Gerald

Steve Wilder wrote:
>   Hello, all.
>
>   I'm using Apache 1.3.29 and  Embperl 1.3.6
>
> I've got two Apache Virtualhosts: www.benwilder, and
> rhyme.benwilder.com
>
> Both sites have a "test1.phtml" which looks like this:
> ----------------------------
> [! use test1; !]
>
> [+ test1::whereami() +]<br>
> ----------------------------
>
> Both sites have a test1.pm file which sits in their Document Root
>
> Live's test1.pm looks like this:
> ----------------------------
> package test1;
>
> sub whereami {
>    return "live";
> }
> 1;
> ----------------------------
>
> Rhyme's test1.pm looks like this:
> ----------------------------
> package test1;
>
> sub whereami {
>    return "rhyme";
> }
> 1;
> ----------------------------
>
> The problem is that if I reload one or the other enough times, it will
> begin using the other sites test1.pm!  I need each site to only use
> it's own test1.pm.
>
> If I restart Apache, the problem goes away for a time, but will come
> back if I reload one or the other enough times.
>
> BTW: In my httpd.conf, I set "PerlSetEnv PERL5LIB" in the VirtualHost
> directive to its own Document Root.
>
> How do I lock each VirtualHost to it's own test1.pm module?
>
> Thanks,
>
> Steve Wilder
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

---------------------------------------------------------------------------
Gerald Richter            ecos electronic communication services gmbh
IT-Securitylösungen * Webapplikationen mit Apache/Perl/mod_perl/Embperl

Post:       Tulpenstrasse 5          D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de          Voice:   +49 6133 939-122
WWW:        http://www.ecos.de/      Fax:     +49 6133 939-333
---------------------------------------------------------------------------
ECOS BB-5000 Firewall- und IT-Security Appliance: www.bb-5000.info
---------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Apache virtulahosts sharing modules

Posted by "Luiz Fernando B. Ribeiro" <lu...@engenhosolucoes.com.br>.
Steve Wilder wrote:
> 
>  Hello, all.
> 
>  I'm using Apache 1.3.29 and  Embperl 1.3.6
> 
> I've got two Apache Virtualhosts: www.benwilder, and rhyme.benwilder.com
> 
> Both sites have a "test1.phtml" which looks like this:
> ----------------------------
> [! use test1; !]
> 
> [+ test1::whereami() +]<br>
> ----------------------------
> 
> Both sites have a test1.pm file which sits in their Document Root
> 
> Live's test1.pm looks like this:
> ----------------------------
> package test1;
> 
> sub whereami {
>   return "live";
> }
> 1;
> ----------------------------
> 
> Rhyme's test1.pm looks like this:
> ----------------------------
> package test1;
> 
> sub whereami {
>   return "rhyme";
> }
> 1;
> ----------------------------
> 
> The problem is that if I reload one or the other enough times, it will 
> begin using the other sites test1.pm!  I need each site to only use it's 
> own test1.pm.
> 
> If I restart Apache, the problem goes away for a time, but will come 
> back if I reload one or the other enough times.
> 
> BTW: In my httpd.conf, I set "PerlSetEnv PERL5LIB" in the VirtualHost 
> directive to its own Document Root.
> 
> How do I lock each VirtualHost to it's own test1.pm module?


Its a common need in web development and the best way I found was to 
develop a base class, say "Clients.pm" and inherit it in each client 
namespace, say "Client_XYZ.pm", example:

Clients.pm:
package Clients;

# Defines methods
# Connects to database, do caching and other common features


Client_XYZ.pm:
package Client_XYZ;

use base Clients.pm;

my $app = Client_XYZ->start;

sub new {
	$app->reload() unless $app->state_valid();
	$app->connect() unless $app->conected();

	retun $app;
}

sub start {
	# Call SUPER->new if needed
	# Do whatever initialization you need
	
	# returns the object
}


This is just a simple scheme but it is the way I have been doing with my 
clients (virtualhosts on same server). This approach creates a namespace 
for each client to avoid conflicts, and you can override, if needed, the 
base class methods.

Its important to note that you should not connect to the database on 
Apache initialization since the database handler will be shared and 
cause problems. Put your connection code on the new method and let each 
instance of apache gets its own handler.

I don't know if this looks too complicated but, as suggested before, we 
can discuss this and other people solutions a bit more if anybody wants.

---
Luiz Fernando B. Ribeiro
Engenho Soluções para a Internet
+55 11 4485-0136

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org