> 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.

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

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

  package MyTools;

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

Now you can create separate instances by coding:

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

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

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


hth,
 ------------------------------------------------------------------------
!  Robert Friberg          0733-839080
!  Developer/Trainer       perl,java,dotnet,linux,xml,uml,sql,c/c++,vb
!  Ensofus AB              http://www.ensofus.se/
!  Miljo Online AB         http://www.miljo-online.se/
 ------------------------------------------------------------------------

> -----Original Message-----
> From: Alexander Shipitsyn [mailto:[EMAIL PROTECTED]
> Sent: Friday, January 23, 2004 9:56 AM
> To: [EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to