Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

DBI Disconnect does nothing!

by expresspotato (Beadle)
on Jun 08, 2009 at 09:09 UTC ( #769424=perlquestion: print w/replies, xml ) Need Help??

expresspotato has asked for the wisdom of the Perl Monks concerning the following question:

Hey, $dbh->disconnect; For some reason isn't working for me... Take the following example:
use DBI; #do("./"); print `netstat | grep "mysql" | wc -l`; $db="billing"; $user="user"; $passwd="me"; $host="localhost:3306"; $connectionInfo="dbi:mysql:$db;$host"; $select = "select id from sometable;"; $dbh=DBI->connect($connectionInfo,$user,$passwd) || print "DBI Conne +ction Failed!($DBI::errstr)"; $sth=$dbh->prepare($select); if (!($sth->execute())) { } @row=$sth->fetchrow_array(); $sth->finish; $dbh->disconnect; print `netstat | grep "mysql" | wc -l`;
It will print the number of mysql connections before and after the script is run. Continually running it you can see the number active connections increases with each run. The connections do eventually time out but that's no help at all. Considering a server could try and handle thousands of requests, without them being disconnected (on demand) the server would quickly grind to a halt. Any help would be appreciated! -Kevin

Replies are listed 'Best First'.
Re: DBI Disconnect does nothing!
by Anonymous Monk on Jun 08, 2009 at 09:20 UTC
    $dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
Re: DBI Disconnect does nothing!
by dHarry (Abbot) on Jun 08, 2009 at 09:21 UTC

    What does

    $dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n";

      $DBI::errstr gives the actual database error message from the last DBI method called. See for more information.

        Hi :) expresspotato needs to insert that code in his program, and report us the error message :)
Re: DBI Disconnect does nothing!
by mje (Curate) on Jun 08, 2009 at 09:22 UTC

    Are the sockets by any chance in a TIME_WAIT state?

Re: DBI Disconnect does nothing!
by arc_of_descent (Hermit) on Jun 09, 2009 at 06:41 UTC

    You're better off checking your mysql connections within mysql, rather than checking the sockets. Its possible that some mysql configs might not use TCP sokets at all.

    Check out the SHOW PROCESSLIST mysql command to view connection info

Re: DBI Disconnect does nothing!
by Anonymous Monk on Jun 08, 2009 at 21:39 UTC
    Hi, Yes the connections are in a Time_wait state... Does this mean the DB actually disconnected?

      Yes, I believe so. Just do a search on google for TIME_WAIT and you'll find out why.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://769424]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2021-10-28 11:43 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (96 votes). Check out past polls.