function mysql_kill_proc($timeout) {
if($timeout == "") $timeout = 60; // might need to change this
$result = mysql_query("SHOW FULL PROCESSLIST");
while ($row = mysql_fetch_assoc($result)){
if($row["Time"] > $timeout AND $row["Command"] == "Sleep" AND $row["Info"] == "" AND $row["db"] <> ""){
mysql_query("KILL ".$row["Id"]);
}
}
mysql_free_result($result);
}
Note that I have not tested this but it SHOULD work.
I couldn't get some SQL processes to hang on purpose so thats why its not tested. Also I would try what Beatles suggested first, adding mysql_close(); to theend.php as this might be considered more of a bandaid than a solution.
If you like I can PM you my cPanel info and oyu can have a mess around and see if you can stop hanging and all that if this mysql_close(); doesn't work.
Put it, say, in a file called mkp.php, and make it include config.php. Best if you DON'T put it in a webserver-accessible location. Then run it every 5 minutes via cron.
Oh, add a line below that actually calling the function, e.g. mysql_kill_proc().