You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by We...@aol.com on 2000/06/12 18:14:56 UTC
Problems with Apache::DBI
Hello,
This message is urgent and could save our banner exchange.
Recently we started growing so fast that we had to convert our entire system
at Traffic-Exchange.com to mysql. Now that this is done we need persistant
database connections to the mysql server. From downloading the Apache::DBI
module I have no idea how to set this up.
But what I can tell you is that we connect to the mysql database 1 time for
every banner that is called by having this in our perl script:
use DBI;
$dbh =
DBI->connect("dbi:mysql:$mysqldatabase","$mysqlusername","$mysqlpassword") ||
die("Couldn't connect to database!\n");
&updatedatabase;
$dbh->disconnect;
Each time a banner is called that code is execuited meaning the database
would open over 1,000 in a few min.
Re: Problems with Apache::DBI
Posted by Drew Taylor <dt...@vialogix.com>.
One other thing: Make sure the 'use Apache::DBI' comes before 'use DBI'
in your startup.pl or httpd.conf file. Very important little step. :-)
Other than that, it's a 5 minute drop in that works wonderfully!
Rob Tanner wrote:
>
> Believe it or not, it's the simplest task in the world. In startup.pl add
> the line "PerlModule Apache::DBI" I'm not sure how it does it's magic, but
> basically, with that module loaded, DBI connection open/close requests go
> through it and it maintains a persistant connection for you (the close is
> replaced with a null, etc, so you don't even have to modify your banner
> module. If you've installed Apache::DBI, simply grab the manpage, but
> basically, all you do is add it to startup.pl. Neat, ain't it!! :-)
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/
Re: Problems with Apache::DBI
Posted by Edmund Mergl <E....@bawue.de>.
Matt Carothers wrote:
>
> On Mon, 12 Jun 2000, Rob Tanner wrote:
>
> > Believe it or not, it's the simplest task in the world. In startup.pl add
> > the line "PerlModule Apache::DBI"
>
> You can either stick "PerlModule Apache::DBI" in your httpd.conf or add
> 'use Apache::DBI ();' to your startup.pl. Also, for mysql, you'll need
> to add a keepalive routine to your startup.pl:
>
> sub Apache::DBI::db::ping {
> my $dbh = shift;
> return $dbh->do('select 1');
> }
>
> - Matt
this is safer:
sub Apache::DBI::db::ping {
my $dbh = shift;
my $ret = 0;
eval {
local $SIG{__DIE__} = sub { return (0); };
local $SIG{__WARN__} = sub { return (0); };
$ret = $dbh->do('select 1');
};
return ($@) ? 0 : $ret;
}
Edmund
--
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.edmund-mergl.de
fon: +49 700 EDEMERGL
Re: Problems with Apache::DBI
Posted by Matt Carothers <ma...@telepath.com>.
On Mon, 12 Jun 2000, Rob Tanner wrote:
> Believe it or not, it's the simplest task in the world. In startup.pl add
> the line "PerlModule Apache::DBI"
You can either stick "PerlModule Apache::DBI" in your httpd.conf or add
'use Apache::DBI ();' to your startup.pl. Also, for mysql, you'll need
to add a keepalive routine to your startup.pl:
sub Apache::DBI::db::ping {
my $dbh = shift;
return $dbh->do('select 1');
}
- Matt
Re: Problems with Apache::DBI
Posted by Rob Tanner <rt...@onlinemac.com>.
Believe it or not, it's the simplest task in the world. In startup.pl add
the line "PerlModule Apache::DBI" I'm not sure how it does it's magic, but
basically, with that module loaded, DBI connection open/close requests go
through it and it maintains a persistant connection for you (the close is
replaced with a null, etc, so you don't even have to modify your banner
module. If you've installed Apache::DBI, simply grab the manpage, but
basically, all you do is add it to startup.pl. Neat, ain't it!! :-)
-- Rob
--On Monday, June 12, 2000 12:14 PM +0000 Webmast98@aol.com wrote:
> Hello,
> This message is urgent and could save our banner exchange.
> Recently we started growing so fast that we had to convert our entire
> system at Traffic-Exchange.com to mysql. Now that this is done we need
> persistant database connections to the mysql server. From downloading
> the Apache::DBI module I have no idea how to set this up.
>
> But what I can tell you is that we connect to the mysql database 1 time
> for every banner that is called by having this in our perl script:
> use DBI;
> $dbh =
> DBI->connect("dbi:mysql:$mysqldatabase","$mysqlusername","$mysqlpassword"
> ) || die("Couldn't connect to database!\n");
> &updatedatabase;
> $dbh->disconnect;
>
> Each time a banner is called that code is execuited meaning the database
> would open over 1,000 in a few min.
>
> From seeng this how is it that I can change this to use your module for
> persistant connections and what is it I need to do.
>
> The README was a bit confusing.
_ _ _ _ _ _ _ _ _ _
/\_\_\_\_\ /\_\ /\_\_\_\_\_\
/\/_/_/_/_/ /\/_/ \/_/_/_/_/_/ QUIDQUID LATINE DICTUM SIT,
/\/_/__\/_/ __ /\/_/ /\/_/ PROFUNDUM VIDITUR
/\/_/_/_/_/ /\_\ /\/_/ /\/_/
/\/_/ \/_/ /\/_/_/\/_/ /\/_/ (Whatever is said in Latin
\/_/ \/_/ \/_/_/_/_/ \/_/ appears profound)
Rob Tanner
McMinnville, Oregon
rtanner@onlinemac.com