Re: Closing DB handler with PerlCleanupHandler

[prev] [thread] [next] [Date index for 2004/11/10]

From: Perrin Harkins
Subject: Re: Closing DB handler with PerlCleanupHandler
Date: 20:30 on 10 Nov 2004
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: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Closing DB handler with PerlCleanupHandler
Batara Kesuma 02:47 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Stas Bekman 02:46 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Batara Kesuma 03:51 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Stas Bekman 04:07 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Perrin Harkins 06:47 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Batara Kesuma 07:37 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Timour Ezeev 15:27 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Perrin Harkins 20:30 on 10 Nov 2004

Re: Closing DB handler with PerlCleanupHandler
Glenn Strauss 08:41 on 10 Nov 2004

Generated at 11:26 on 21 Dec 2004 by mariachi v0.52