On Tue, Jan 31, 2006 at 01:23:12PM -0800, Tyler MacDonald wrote: > Apache::DBI and DBI's connect_cached both claim to keep your database > handles fresh and happy, but I've had numerous problems trying to get either > of them to work properly. If a database connection is dropped, sometimes I'd > have to refresh the page two or three times before the "internal server > error" goes away and my webpages are happily reconnected to the database > again. > > Part of the problem seems to be that disconnecting a database handle doesn't > always remove it from {CachedKids}. At least, in the case where DBI thinks > it's already disconnected, it doesnt bother removing it.
It shouldn't need to because the DBI's connect_cached() only returns a handle if it's Active and ping() returns true. Neither should be true for a disconnected handle. Apache::DBI::connect also checks the cached handle using ping. The ping can be tuned via Apache::DBI->setPingTimeOut so it's only called once every few seconds. Perhaps some code somewhere has done that and that's why you're seeing problems. > Anyways, here's what I've done to solve the problem (i'm using postgres): > > - always use connect_cached, don't use Apache::DBI connect_cached actually calls Apache::DBI::connect behind the scenes if Apache::DBI is loaded first (as per the docs). > - use this as my PerlPostConfigHandler: > [...] > - use this as my PerlPreConnectionHandler: > [...] Seems like hack without actually identifying the source of any problem in the existing DBI or Apache::DBI code. With a little more digging I'm sure you could identify _why_ Apache::DBI::connect is giving you back a dead handle. Fixing that would 'help save the world' for countless other users. Can you try that? Tim.