Apache::DBI / connect_on_init not setting dbi_connect_method but later connect() calls do
Apache::DBI / connect_on_init not setting dbi_connect_method but later connect() calls do
am 02.01.2009 19:13:14 von mjy
Hi,
I'm trying to initiate connections in startup.pl for later use (mod_perl
1.xx):
(startup.pl):
use Apache::DBI;
....
Apache::DBI->connect_on_init(
'dbi:Pg:dbname=mydb;host=myhost;port=5432',
'nobody','');
Later, I am attempting to reuse these connections in an Apache::Registry
script using
use DBI;
$dbh=DBI->connect('dbi:Pg:dbname=mydb;host=myhost;port=5432' ,'nobody','');
Now what happens is that each Apache child opens 2 connections to this DS
and presumably the one from startup.pl isn't used. The reason for this
seems to be that the call from startup.pl does not set dbi_connect_method,
while the second call sets it to 'Apache::DBI::connect'. The
Apache::DBI::connect method reuses and caches connections based on a key
that includes this (from the option hash presumably), so the keys differ
for those 2 calls:
first key ($Idx printed from Apache::DBI::connect):
dbname=mydb;host=myhost;port=5432^\nobody^\^\AutoCommit=1^\P rintError=1^\Username=nobody
second key:
dbname=mydb;host=myhost;port=5432^\nobody^\^\AutoCommit=1^\P rintError=1^\Username=nobody^\dbi_connect_method=Apache::DBI ::connect
Can this be avoided somehow so that only 1 connection is initiated and
reused? Is my DBI(1.53) or Apache::DBI(1.04) too old? Is it a bad idea to
set dbi_connect_method explicitly in startup.pl?
Thanks,
Marinos
Re: Apache::DBI / connect_on_init not setting dbi_connect_methodbut later connect() calls do
am 02.01.2009 21:09:12 von Philip Gollucci
> Apache::DBI->connect_on_init(
> 'dbi:Pg:dbname=mydb;host=myhost;port=5432',
> 'nobody','');
> Can this be avoided somehow so that only 1 connection is initiated and
> reused? Is my DBI(1.53) or Apache::DBI(1.04) too old? Is it a bad idea to
> set dbi_connect_method explicitly in startup.pl?
1.07 is 'borked', use 1.06, 1.04 I forget, but I know bugs that matter
were fixed between the 2.
in startup.pl, make sure you load them in this order:
use Apache2::Status ();
use Apache::DBI ();
#$Apache::DBI::DEBUG = 2;
use DBI ();
--
------------------------------------------------------------ ------------
Philip M. Gollucci (pgollucci@p6m7g8.com) c: 703.336.9354
Consultant - P6M7G8 Inc. http://p6m7g8.net
Senior System Admin - RideCharge, Inc. http://ridecharge.com
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70 3F8C 75B8 8FFB DB9B 8C1C
Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.
Re: Apache::DBI / connect_on_init not setting dbi_connect_methodbut later connect() calls do
am 02.01.2009 21:09:31 von Philip Gollucci
> Apache::DBI->connect_on_init(
> 'dbi:Pg:dbname=mydb;host=myhost;port=5432',
> 'nobody','');
> Can this be avoided somehow so that only 1 connection is initiated and
> reused? Is my DBI(1.53) or Apache::DBI(1.04) too old? Is it a bad idea to
> set dbi_connect_method explicitly in startup.pl?
1.07 is 'borked', use 1.06, 1.04 I forget, but I know bugs that matter
were fixed between the 2.
in startup.pl, make sure you load them in this order:
use Apache2::Status ();
use Apache::DBI ();
#$Apache::DBI::DEBUG = 2;
use DBI ();
Apache::DBI->connect_on_init(
--
------------------------------------------------------------ ------------
Philip M. Gollucci (pgollucci@p6m7g8.com) c: 703.336.9354
Consultant - P6M7G8 Inc. http://p6m7g8.net
Senior System Admin - RideCharge, Inc. http://ridecharge.com
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70 3F8C 75B8 8FFB DB9B 8C1C
Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.