perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Peters <mpet...@plusthree.com>
Subject Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")
Date Mon, 30 Jun 2008 15:15:03 GMT
Tobias Kremer wrote:
> Quoting Michael Peters <mpeters@plusthree.com>:
>> Why are you storing the DB handle in a global variable?
>> If you do that then Apache::DBI can't help you if the connection goes away.
> 
> To make this variable available to all Mason components. 

Then use a method to do this, not a global variable. Have that method call
DBI->connect every time you want to get the handle. If Apache::DBI has already
made the connection it will return a cached handle for you. No need to try
caching it on your own. It will only cause problems because it means you're not
using Apache::DBI's cache.

> Theoretically, this
> shouldn't be a problem because I'm (re-)connecting on every request in the
> handler() subroutine not once during startup. 

You're trying to do too much work. Let Apache::DBI worry about connecting,
reconnecting, caching, etc.

> Actually it works perfectly as
> soon as you remove the one-time connection made during startup (LostFoo) which
> just preloads some data from the database.

Except for all those timeout errors you mention :)

> According to the docs Apache::DBI
> should automatically avoid caching this connection.

Apache::DBI doesn't store the cached handle, but your application does. That's
the problem. Apache::DBI can't get rid of that handle if you're storing it
someplace and then trying to use it later.

-- 
Michael Peters
Plus Three, LP


Mime
View raw message