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).
That means that you are either using the wrong database information somewhere or using the wrong (cached) data somewhere, and either one could be caused by closures or by mismanaged globals. It's a bit hard to tell which is happening here. One thing you can do is run httpd -X to make it run a single process, and hopefully that will help you reproduce the problem consistently. Then you can add debugging info or run it in the debugger.
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;
You don't need all of that PerlModule stuff in httpd.conf if you're going to pull them in here.
Apache::DBI->connect_on_init('DBI:mysql:rostering_london:localhost', 'username', 'password',
It doesn't really look like that, does it? You have the real name/pass in there, right?
Every time I need database access, I simply do a:
my $dbh = DBI->connect($dbstr,$dbuser,$dbpass)
Skylos was guessing you had closure problems from doing this. However, if these are always globals, you will not get closures from this. What you need to look for is some place where you are either using $dbstr and friends as lexicals (my $dbstr), or referring to a $dbh that was defined outside of the sub you're using it in, e.g.
my $dbh = DBI->connect($dbstr,$dbuser,$dbpass);
sub foo { my $x = $dbh->prepare.... }
If you haven't already, turn on strict and warnings to help you.
# Import some variables use vars qw( %config %help $dbstr $dbuser $dbpass $debug ); use ORS::Main qw( %config %help $dbstr $dbuser $dbpass $debug );
Don't do both. You are overwriting the "use vars" with your import here where the variable names are the same. That is probably not what's causing you trouble here though.
As Skylos also pointed out, a common approach for handling these things is to have a singleton class. If that sounds too confusingly OO for you, just think of a simple utility function that you always call to get a $dbh:
package ORS::DBUtil; use strict; use warnings; use Apache;
sub get_dbh { my $r = Apache->request; my $dbstr = $r->dir_config('DBASE'); my $dbuser = $r->dir_config('DBUSER'); my $dbpass = $r->dir_config('DBPASS'); return DBI->connect($dbstr,$dbuser,$dbpass); }
# elsewhere... my $dbh = ORS::DBUtil::get_dbh();
- Perrin
-- 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