perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Perrin Harkins <>
Subject Re: Closing DB handler with PerlCleanupHandler
Date Wed, 10 Nov 2004 20:30:26 GMT
On Wed, 2004-11-10 at 02:37, Batara Kesuma wrote:
> > Also, why do you want to avoid persistent connections?
> Because the DB is running out of memory just to keep the persistent
> connections, I just want to try it without persistent connections and
> see the result. If the overhead is not too big, I might just change it
> to use normal connections.

Okay.  I did something like that recently by adjusting the timeout on
the database side.  This was a MySQL database and we set the
wait_timeout very low (15 seconds).  If you use Apache::DBI, it just
reconnects when necessary.  If you are using your own globals to hold
persistent handles, you can get in trouble doing this.

> I tried this to disconnect the handler in PerlCleanupHandler, but it
> didn't work.
> sub handler {
>     my ($r) = @_;
>     our $dbh;
>     if ($dbh) {
>         print STDERR "Got ya!!";
>         $dbh->disconnect();
>     }

That won't work because this is not the same package that the other $dbh
is declared in.

> How can I disconnect 'our
> $dbh' created by scripts within ModPerl::Registry in PerlCleanupHandler?

The package that ModPerl::Registry puts your script in is the same every
time.  You can see it by printing out the value of __PACKAGE__ in your
script.  Then access it as $Full::Name::Of::Package::dbh.

If you use Apache::DBI, all of the handles up in a nice clean hash that
you can go through and disconnect in a cleanup handler.  There's also
probably a way to ask DBI what connections are open.

- Perrin

Report problems:
Mail list info:
List etiquette:

View raw message