I tend to write my apps in a modular fashion, so that each module
connects to the database and fetches its data and then disconnects.
Often, a program will require data from several modules resulting in a
lot of wasted connect/disconnect ops.  Apache::DBI does solve this
issue, but I don't want nor need to keep lingering connections for a
lightly-used application.  (The DB is not used for the majority of
hits to the site.)

I see two possible solutions here:

1) use a cleanup handler to run thru Apache::DBI's connection cache
   and disconnect them

2) roll my own.

Right now I've got an implementation of option 1, but I am not sure
how it interacts with auto-rollback from Apache::DBI.

Here's the function from my startup.perl script:

sub My::DBICleanup {
  my $connection_href = Apache::DBI::all_handlers();

  return unless $connection_href;

  foreach my $key (keys %$connection_href) {
    delete $connection_href->{$key};
    warn "DBIClenaup Purged connection $key\n";
  }
}

Apache->push_handlers('PerlCleanupHandler', \&My::DBICleanup);

My guess is that my handler will clearnup the cache before
Apache::DBI's handler gets a chance to auto-rollback.  Is this some
feature others may want?  Perhaps a new feature to Apache::DBI's
cleanup handler might be the way to go?

Any comments?

Reply via email to