[CDBI] Forking and reconnecting to the database

Perrin Harkins perrin at elem.com
Tue Mar 7 20:44:44 GMT 2006

On Tue, 2006-03-07 at 19:41 +0000, Aaron Trevena wrote:
> I've been reading about how to handle CDBI classes when forking and am
> struggling to get a grasp of the picture - naturally, there's no clear
> explaination in the cdbi or Ima::DBI docs anywehere, so I have found
> pieces of the puzzle like :
> http://www.spanner.org/lists/cdbi/2005/11/07/eb3bb63e.html
> .. which explains that I need a new connection after forking and using
> $dbh->{InactiveDestroy}, but it looks like I need subclass the
> connection methods of either Ima::DBI or Class::DBI and thats more
> work and less documentation that i'd really like.

Nevertheless, you really do need to do it if you want to use Class::DBI
safely in a forking server.  The code in the above post came from a lot
of difficult debugging of a forking perl daemon, just like what you're
describing, and it's significantly trickier to make that work than just
getting Class::DBI to be mod_perl-safe.  We didn't even notice the
problem until we had an initial version in production because it's very

We've been using this code long enough now that I'm confident in it.  I
should update Ima::DBI with it.  However, you will still need to set
InactiveDestroy in your code.  Meanwhile, the simplest thing you can do
is to make this modification to your local Ima::DBI.  You could push
these changes into db_Main in your Class::DBI base class instead, if
you're familiar with that code.

- Perrin

More information about the ClassDBI mailing list