I'm doing some testing (on my dev server) to help me figure out what is causing the ever growing list of connections on my production server. My assumption is that there are certain pages that are not closing the connection using mysql_close(). So I'm trying to first of all confirm what is creating the connections, and then confirm how to make sure they're closed.
To do this I created a simple script to create a connection, followed by a mysql_close() to close the connection. Unfortunately, my testing is at a standstill because I can't even confirm that I'm creating connections.
When I execute the following code (notice mysql_close()) is commented out, I would expect to see a new connection in my client connections list, and I would expect it to kill itself after 20 seconds since I've set the wait_timeout to 20. However, no connection even seems to be created.
<?php
$dblocation = "127.0.0.1";
$dbusername = "blah_dev";
$dbpassword = "test";
$dbname = "blah_dev";
$dbdescription = "";
$conn = mysql_connect($dblocation, $dbusername, $dbpassword) or die ("<span style='color:red'>Unable to connect! Press F5 to try again.</span>");
mysql_select_db($dbname, $conn) or die ("Unable to select database!");
$sql = "select fullname from months";
$result = mysql_query($sql);
if($row = mysql_fetch_array($result)){
echo "<table border=1>";
do{
$month = $row["fullname"];
echo "<tr><td>".$month."</td></tr>";
}while ($row = mysql_fetch_array($result));
echo "</table>";
}
//mysql_close();
?>
I even added a simple select statement to confirm that I'm making a connection, and I am. Why does this connection not show in my Client Connections list in MySQL Workbench? I'm also using another tool (MySQL Diagnostic Manager) to show me the current threads and it's not showing there either.
What am I missing here?
Turns out, this code does create a client connection, but because it closes it as soon as the script finishes running it does not appear to be creating a connection. :/