Ah, the closure problem. Subroutines inside of your asp scripts behave as closures.
virtualhost A sets variables... and declares a subroutine that uses these variables. an access to virtualhost B accesses the same subroutine - which is already loaded with variables per the virtualhost A in closure sense. Essentially the context of the subroutine for its external variable inheritance is the first place it was declared, not your current place. My solution to this problem is to pass EVERYTHING. I don't rely on any subroutine to know Any data that isn't passed to it *explicitly*. Using global or even local or even package variables is baad here. This even goes for things like $Request and $Response. (try referencing a $Response instance that is already served and gone - a most excellent excersize in not working!) And that is how I got around this... feature - artifact - method of operation... that is the way of life in mod_perl. I advise either instancing yourself your own object to hold your variables which holds all your methods (subroutines), or passing all these values to your subroutines, or defining your subroutines at execution time to anonymous variables. This guarantees their autonomy, like this: my $main = sub { $Response->write("The global variable is $wofwof\n"); } *draws big red VARIABLES DO NOT CROSS HERE* lines around a subroutine definition. ideally, each virtualhost would get its own isolated processes. But if you wanted that, you'd be using windows IIS and activestate, wouldn'tcha? :P Skylos On Thu, 11 Mar 2004, Brett Randall wrote: > Hi everyone > > I have a problem that I can't figure. I've got two virtual hosts on > one server. They both point to different directories as the > DocumentRoots, however the mod_perl scripts in each directory are > identical in name and content. > > My problem is that SOMETIMES while accessing one virtual host, it will > appear as though it is actually pulling data from the other virtual > host's database (each virtual host uses a different database as shown > below), however the URL does not change. All the links, etc, continue > to point to the right domain, however the data is just wrong (and only > intermittently). > > Here is how the two virtual hosts are declared in httpd.conf: > > ------------------------------------------------------------------------ > <VirtualHost 12.34.56.78> > ServerName demo.domain.com > ServerAdmin [EMAIL PROTECTED] > DocumentRoot /var/www/ors/demo > ErrorLog /var/www/ors/logs/demo-error_log > CustomLog /var/www/ors/logs/demo-access_log common > PerlModule Apache::Registry > PerlModule Apache::DBI > PerlRequire /var/www/ors/demo/startup.pl > PerlFreshRestart On > PerlWarn on > PerlSetVar DBASE DBI:mysql:host=localhost;database=rostering_demo > PerlSetVar DBUSER username > PerlSetVar DBPASS password > > <Directory /var/www/ors/demo> > <Files ~ "\.pl$"> > SetHandler perl-script > PerlHandler Apache::Registry > PerlSendHeader On > </Files> > Options ExecCGI Indexes MultiViews FollowSymLinks > Order allow,deny > Allow from all > </Directory> > </VirtualHost> > > <VirtualHost 12.34.56.78> > ServerName london.domain.com > ServerAdmin [EMAIL PROTECTED] > DocumentRoot /var/www/ors/london > ErrorLog /var/www/ors/logs/london-error_log > CustomLog /var/www/ors/logs/london-access_log common > PerlModule Apache::Registry > PerlModule Apache::DBI > PerlRequire /var/www/ors/london/startup.pl > PerlFreshRestart On > PerlWarn on > PerlSetVar DBASE DBI:mysql:host=localhost;database=rostering_london > PerlSetVar DBUSER username > PerlSetVar DBPASS password > > <Directory /var/www/ors/london> > <Files ~ "\.pl$"> > SetHandler perl-script > PerlHandler Apache::Registry > PerlSendHeader On > </Files> > Options ExecCGI Indexes MultiViews FollowSymLinks > Order allow,deny > Allow from all > </Directory> > </VirtualHost> > ------------------------------------------------------------------------ > > The startup.pl files are like: > > ------------------------------------------------------------------------ > #!/usr/bin/perl > use Apache::DBI; > use Apache::Registry; > use Apache::RegistryLoader; > use DBI; > use DBD::mysql; > use strict; > > Apache::RegistryLoader->new->handler("/roster.pl", > "/var/www/ors/london/roster.pl", > "london.domain.com"); > > Apache::DBI->connect_on_init('DBI:mysql:rostering_london:localhost', > 'username', > 'password', > { RaiseError => 0, > AutoCommit => 1, > PrintError => 1 } ) > or die $DBI::errstr; > > Apache::DBI->setPingTimeOut('DBI:mysql:rostering_london:localhost', 60); > 1; > ------------------------------------------------------------------------ > > (and the other is identical other than the handler and connect_on_init > lines) > > roster.pl is the main script, which simply use's a package in ./ORS/ > and then calls its main() sub. The main() sub in this package then > does: > > ------------------------------------------------------------------------ > use Apache; > my $r = Apache->request; > $dbstr = $r->dir_config('DBASE'); > $dbuser = $r->dir_config('DBUSER'); > $dbpass = $r->dir_config('DBPASS'); > ------------------------------------------------------------------------ > > Every time I need database access, I simply do a: > > my $dbh = DBI->connect($dbstr,$dbuser,$dbpass) > > I've made these variables available throughout the entire package by > using a use vars qw() in the BEGIN of this package, and I've made them > available to other packages by exporting them. Below is how I did > this: > > ------------------------------------------------------------------------ > BEGIN { > > use vars qw( > %config > %help > $dbstr > $dbuser > $dbpass > $debug > ); > > use Exporter (); > @ORS::Main::ISA = qw(Exporter); > @ORS::Main::EXPORT_OK = qw( > %config > %help > $dbstr > $dbuser > $dbpass > $debug > ); > } > > use vars @ORS::Main::EXPORT_OK; > use vars qw/$action/; > use ORS::Subs qw(:DEFAULT); > > sub main { > ------------------------------------------------------------------------ > > They are then imported into other packages with: > > ------------------------------------------------------------------------ > BEGIN { > > # Import some variables > use vars qw( > %config > %help > $dbstr > $dbuser > $dbpass > $debug > ); > use ORS::Main qw( > %config > %help > $dbstr > $dbuser > $dbpass > $debug > ); > } > ------------------------------------------------------------------------ > > I hope I have provided all the info I need... I've been working on > this software for about 12 months flawlessly and have only just tried > using it on multiple virtual hosts to encounter this problem. I'm sure > its more my methodology than anything so any help/pointers on how best > to do this would be great! > > Thanks, > > Brett Randall. > > -- > Report problems: http://perl.apache.org/bugs/ > Mail list info: http://perl.apache.org/maillist/modperl.html > List etiquette: http://perl.apache.org/maillist/email-etiquette.html > > - [EMAIL PROTECTED] - The best part about the internet is nobody knows you're a dog. (Peter Stiener, The New Yorker, July 5, 1993) - Dogs like... TRUCKS! (Nissan commercial, 1996) - PGP key: http://dogpawz.com/skylos/mykey.asc -- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html