http://qs321.pair.com?node_id=769424

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("./sql.pl"); 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";
    gives?

      $DBI::errstr gives the actual database error message from the last DBI method called. See DBI.pm 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


    --
    Rohan
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.