perl-asp mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Shipitsyn <s...@omsu.ru>
Subject Re[2]: Multiple virtual hosts and same pm-modules names errors
Date Fri, 23 Jan 2004 11:22:19 GMT
Hello!

Friday, January 23, 2004, 3:59:09 PM, you wrote:

>> I known about issue "Why do variables retain their values between
>> requests?" in FAQ and I always use my()/local() for not retain values
>> of variables between requests.

RF> This applies to asp pages because they are wrapped in a subroutine,
RF> "my" variables then become local to the current request. This
RF> doesn't apply to "my" variables of modules. Additionally, perl will
RF> always load the same module (first one it finds in traveling @INC) if
RF> there are duplicates.


.htaccess for site1:
SetEnv PERL5LIB /home/omsu/site/lib/pm


.htaccess for site2:
SetEnv PERL5LIB /home/omsutech/site/lib/pm


These directives allows to mod_perl/Apache::ASP mix up modules with
same names from different directories ???




See also my questions later in this text.


RF> Here's a possible solution:
RF> Make your module object oriented and put the module variables in an
RF> object instance. Store the object instance in your Application or
RF> Session hash, whichever applies.

RF>   package MyTools;

RF>   #my %cache = (); #NO,NO,NO becomes global in httpd child process
RF>   sub new
RF>   {
RF> 	my %cache = (); #local to the sub, ok
RF> 	return bless {cache => \%cache}, shift;
RF>   }

RF> Now you can create separate instances by coding:

RF>    my $obj1 = MyTools->new();
RF>    my $obj2 = MyTools->new();

RF> Now, each object gets its own cache. If you want a single object
RF> to share across the entire application then create it in
RF> Application_OnStart (global.asa) and keep a reference in the
RF> $Application object.

RF> In this scenario both sites will have separate data but share the same code.
RF> If your going to do development also on the modules this is not enough
RF> because you are also affecting the production site. Instead you should run
RF> a separate httpd for the development site. I find it often necessary to
RF> restart or reload httpd during development so for me a that is the
RF> obvious choice.

Thanks, Robert!

But... Let:

I need to have different code (and same module names!) for production
and development site.

Also I need to have (for example) two different production sites
(production sites for company A and company B) (site-A-production and
site-B-production), developed with same module naming conventions (for
example, each production site (A and B) have pm-module with name
"Tools.pm" and different code of each Tools.pm). For example, my
programming style is to use in web-pages my service module named
"Tools.pm" developed specially for each site.

And for each of production sites (A and B) I need to have development
version of site (site-A-dev and site-B-dev) with different code of
modules.


Ok, general question about hosting multiple sites (virtual hosts).
==================================================================

Assume that I need to host 10 (or 50) Apache::ASP-based sites. Assume
that each site have private module "Tools.pm" with globally-unique
code. Assume that I need to have one httpd build configured for
processing by child-httpd more than 1 user request (user request for
random hosted site). Assume that I need to use only one IP-address and
only port 80 on this IP-address with one httpd build (one root
instance in memory with 10 child processes).


How to solve this problem with modules mixing in this case ???









>> -----Original Message-----
>> From: Alexander Shipitsyn [mailto:ship@omsu.ru]
>> Sent: Friday, January 23, 2004 9:56 AM
>> To: asp@perl.apache.org
>> Subject: Multiple virtual hosts and same pm-modules names errors
>>
>>
>> Hello!
>>
>> I have problem with caching of compiled my .pm modules (auto-compiled
>> in memory by Apache::ASP and mod_perl) with same names for different
>> sites on same Apache::ASP/apache machine.
>>
>> I have 2 virtual hosts:
>>
>>   "site1" is for production site
>>   (homedir is .../site1)
>>
>>     and
>>
>>   "site2" is for developing site.
>>   (homedir is .../site2)
>>
>> Homedirs are different.
>>
>> I copied all files of site "site1" to home directory of site "site2"
>> (Apache::ASP is configured via .htaccess files located in different
>> site1 and site2 home directories).
>>
>> Let my http-request-1 for site1 hit on apache-child-process-A and then
>> my http-request-2 for site2 hit on same apache-child-process-A
>> (apache-child-process-A processes multiple requests before die of
>> apache-child-process-A).
>>
>> During process of http-request-2 for site2, apache-child-process-A
>> uses cache of my module Tools.pm from site1. This is some error for
>> me!!! In fact, pm-module for site1 is used on site2 and module for site2
>> is not used.
>>
>> If each apache-child-process processes only 1 request and then die,
>> then all is Ok, no error occurs.
>>
>> I known about issue "Why do variables retain their values between
>> requests?" in FAQ and I always use my()/local() for not retain values
>> of variables between requests. I have no problem with retain of
>> variable values between requests. I have problem with messing modules
>> with same names by Apache::ASP or/and by mod_perl.
>>
>> If I change all names of used modules for site2 (e.g. Tools.pm ->
>> Tools2.pm) or (seems to me; I not sure) change name of directory of
>> site2 where Tools.pm is located inside of site2 root, then no errors
>> occurs with using modules with same names in site1 and site2 code.
>> This is bad method for avoid described error.
>>
>> I have not special pre-compiled modules; all my pm-modules exists only
>> in sources like Tools.pm.
>>
>>
>> My .htaccess settings is (selected):
>> ------------------------
>> PerlSetVar NoState 0
>> PerlSetVar NoCache 1
>> PerlSetVar StatINC 1
>> PerlSetVar UseStrict 1
>>
>> PerlSetVar StateDir /tmp/omsu_asp
>> (^-- for site1)
>>
>> PerlSetVar StateDir /tmp/omsutech_asp
>> (^-- for site2)
>> ------------------------
>> Note: StateDir is different for site1 and site2
>>
>>
>>
>> My Tools.pm begin is:
>> -----------------
>> package omtools;
>> use strict;
>> require Exporter;
>> our @ISA = qw(Exporter);
>> our @EXPORT = qw(sq utf8to1251 win1251toutf8 alltrim unicode2win);
>> use Unicode::MapUTF8 qw(from_utf8 to_utf8);
>> use Unicode::Map;
>> use String::Strip;
>> use XML::DOM;
>>
>> sub bla-bla-bla...
>>
>> 1;
>> -----------------
>>
>>
>>
>> Using of my modules in pages code is:
>> --------------------
>> use locale;
>> use POSIX;
>> use Time::localtime qw(localtime);
>>
>> use omtools;
>> use sysvar;
>> use funcs;
>>
>> use XML::DOM;
>>
>> setlocale(LC_CTYPE, "ru_RU.cp1251");
>>
>> my $time_start = ctime(time);
>>
>> bla-bla-bla
>> -----------------
>> Note: my pm-modules is omtools, sysvarm, funcs
>>
>>
>>
>> Help me to solve this problem!
>>
>> (My main task at this stage is make full clone of site1 on same
>> Apache::ASP/apache engine)
>>
>>
>> Thanks!
>>
>>
>>
>> --
>> Best regards,
>>  Alexander                          mailto:ship@omsu.ru
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
>> For additional commands, e-mail: asp-help@perl.apache.org


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




-- 
Best regards,
 Alexander                            mailto:ship@omsu.ru


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


Mime
View raw message