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

Peter Karman peter at peknet.com
Mon Jul 28 14:43:40 EDT 2008



On 07/28/2008 01:30 PM, Mark Stosberg wrote:
>>> 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);
> 

http://search.cpan.org/~timb/DBI-1.607/DBI.pm#connect_cached

-- 
Peter Karman  .  peter at peknet.com  .  http://peknet.com/



More information about the cgiapp mailing list