perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Perrin Harkins <phark...@gmail.com>
Subject Re: Disconnect database connection after idle timeout
Date Fri, 14 Nov 2014 13:30:18 GMT
On Fri, Nov 14, 2014 at 7:58 AM, Vincent Veyron <vv.lists@wanadoo.fr> wrote:

> If I understand correctly, I could also use Apache::DBI and a persistent
> connection for a similar result, modulo what you wrote in an earlier
> message regarding the connection being more explicit (which I don't quite
> grasp, I'll have to study on that)?


Right. Apache::DBI overrides DBI->connect() when loaded so that a normal
connect() call gets a cached handle if available.

What you're doing here looks fine. If you ever switch off AutoCommit in
your code, I'd suggest adding a cleanup handler that checks if the handle
is not currently in AutoCommit mode, and if not, issues a rollback and
switches it to AutoCommit. That protects against an exception leaving your
database handle in a bad state. (Apache::DBI tries to do that
automatically, but it's not very smart about it. It only happens if you
have AutoCommit off when you connect.)

- Perrin

Mime
View raw message