Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl DBI - automatic disconnect possible?

Wondering if possible to make the DBI disconnect handles automatically

         

bigperm

4:33 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



Hello all...

One of the main problems our system has experienced is the "too many connections" error with MySQL. We can go in, do a "show processlist", and a great number of processes will just be sitting there, sleeping.

One problem is the timeout...I believe it defaults to around 7 hours. That's easy enough to change. An hour is what we're planning on changing it to.

The second problem is the number of connections, which was sitting at 500. I don't know an acceptable number for this. The server has 4 P-II-400's.

The third problem is the code itself. Many old scripts don't disconnect properly. We're planning on going through these, but there's a lot to do.

What I'm wondering is this: is it possible to have the Perl DBI ->disconnect database handles automatically when the script is exited, or exec's to another script? In other words, is there an option somewhere for this? I may be crazy, but I really thought I read in O'Reilly's "Programming the Perl DBI" book that you did not have to explicitly disconnect database handles.

Thanks very much in advance for any help.

I really don't expect that the "auto disconnect" is available, but it's worth a shot. Also, if someone can give me a good number for maximum connections allowed, I would greatly appreciate it.

Dale

coopster

6:31 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, bigperm.

The number of connections [dev.mysql.com] to use all depends on your OS. Also, it is good practice to always disconnect [oreilly.com] before ending a script.

bigperm

6:38 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



I should have mentioned the OS...sorry about that. It's Linux...an older version of Red Hat but the kernel is 2.4.20-20.9.

Thanks for the info, and thanks for the welcome!

Dale

Monus

10:11 am on Mar 14, 2005 (gmt 0)

10+ Year Member



We use this in our scripts for to auto disconnect from the database.


END {
# Disconnect from the database.
$dbh->disconnect() if ($dbh);
}