On 29/07/2008, at 04:58 AM, Michael Peters wrote:

Mark Stosberg wrote:

the different process_id (2461, 2780) means they are two different
connections ?
I think that's right. I'm not a FastCGI user, but it's my understanding that you would need a
variable to be at least package-scoped for it to be share.
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.

I believe the way around this is to use the package variable approach Mark suggests with a C::A::P::DBH callback. DBI's connect_cached option, is designed to handle the stale connection problem (I use DBI directly, but the principle is the same):

# Use a callback to create your owh handle that is still lazy loaded
    $self->dbh_config(sub { DBI->connect_cached(); });



#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################

Reply via email to