[cgiapp] Re: is my app caching db connection ?

Mark Stosberg mark at summersault.com
Mon Jul 28 14:30:36 EDT 2008


> > If I'm right, then something like this would stay shared:
> > 
> > our $dbh = DBI->connect(...);
> > $self->dbh_config($dbh);
> 
> But don't do that. It's just asking for problems. DB connections *will* 
> go stale. If that happens your application will stop working with 
> strange errors and only a restart will fix it. This is the problem that 
> Apache::DBI solves for mod_perl. If you want to learn how to do this on 
> your own, then I suggest looking in there for some pointers. But I will 
> warn you that Apache::DBI doesn't do the magic on it's own. DBI knows 
> about Apache::DBI. So any code you write yourself won't have that advantage.

Michael is right. The DBH plugin does have a way to cope with this, though.
Like this:

 our $dbh = sub { DBI->connect(...) }
 $self->dbh_config($dbh);

If we ever can't ping the connection, we'll call the code ref again and
re-connect.

I have personally used Apache::DBI/mod_perl for this in the past, but would
like to know that's there's a solution for FastCGI as well.

    Mark




More information about the cgiapp mailing list