[cgiapp] cached DBI connections with cgiapp/fastcgi

Michael Peters mpeters at plusthree.com
Wed Oct 22 13:39:30 EDT 2008


Benjamin Hitz wrote:

> So - I hope this is a useful summary for people who are still trying 
> this - and also I am hoping that someone has some insight on why my $dbh 
> goes stale.  It was my understanding that $self->dbh_config would 
> reconnect if the handle went "bad" but probably I am misunderstanding 
> something.

It will probably reconnect if the handle isn't there. But not if it goes bad. I don't know for sure 
since I don't use that plugin. But it's a common problem when dealing with persistant DB 
connections. If you want to see how mod_perl folks handle, take a look at Apache::DBI. Look at it's 
connect() method and particularly how it uses ping().

A lot of it is magic so things just work under mod_perl and so you don't need to wrap your DBI 
calls. You could make a similar FastCGI::DBI module if you wanted to (and put it on CPAN so others 
can use it too), or just wrap all of your DBI->connect calls with something like this.

It's not trivial to get it 100% correct and if you weren't using Oracle (which has such a high cost 
for creating connections) and instead using PostgreSQL or MySQL then I'd say don't bother. But since 
you are using Oracle it's probably worth doing.

-- 
Michael Peters
Plus Three, LP



More information about the cgiapp mailing list