Re: Disconnect database connection after idle timeout
Perrin Harkins <[email protected]>
| Newsgroups | gmane.comp.apache.mod-perl |
|---|---|
| Message-ID | <CAC0_be17hTepR_oXsYgq-Q56qj-Z++pmf3dgE5-mCxnP11Lq5A@mail.gmail.com> |
On Fri, Nov 14, 2014 at 7:58 AM, Vincent Veyron <[email protected]> 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