[CDBI] Re: Class::DBI and mod_perl

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Tue Nov 21 23:29:23 GMT 2006


> My question is: Have any changes been made since this wiki entry that
> mean that I don't have to worry about any kind of additions to my code
> or Apache::DBI?

No. Everything in that wiki entry is still applicable. There was talk of a
patch to Ima::DBI that would have made CDBI work with mod_perl correctly
right out of the box, but either Tony never released it or Perrin never
submitted it to him. Perrin's patch isn't intended to be used with
Apache::DBI at all, in case that wasn't clear.

Personally, I still use Apache::DBI and then install my own
PerlCleanupHandler to automatically rollback any uncommitted transactions.
This happens extremely rarely in practice.

I just did a CPAN search to look up the changelog for Ima::DBI and I noticed
Apache::DBI::Cache and Apache::DBI::Cache::ImaDBI. This is the first I've
heard or seen of these modules. They claim to address this issue in some
fashion. Probably worth investigation!

> And what is the best way to ensure that Class::DBI uses persistent
> connections?

CDBI always uses persistent connections through the use of a closure. Indeed,
that's the problem with using Apache::DBI with Class::DBI. Since Class::DBI
never calls DBI->disconnect(), Apache::DBI's automatic rollback is not
performed under mod_perl.

> Do I just "use Apache::DBI" in my main CDBI package for each of my apps, or
> do I just use "PerlModule Apache::DBI" in my httpd.conf?

Well, I put the following in my startup.pl file:

use Apache::DBI;
use DBI;
DBI->install_driver('...');

Then, I specify my PerlCleanupHandler in httpd.conf.

> Also, I'm looking at moving to mod_perl2 at some point over the next 6
> months. Anything important I should know about CDBI/Apache::DBI in
> that version?

No. I've been using CDBI/Apache::DBI/mod_perl2 in a production environment
for a couple years now. It's not a problem.

The main problem you *might* encounter with mod_perl and CDBI, which is not
addressed by the wiki, is CDBI's "Live Objects" cache. You have to be very
careful with your scoping if you want to use that cache. If not or you
experience problems, it's easily deactivated. But it is good discipline for
reducing memory leaks, I think.



More information about the ClassDBI mailing list