Here's the code:
<?php mysql_connect('yourhost', 'username', 'password'); $res = mysql_query("SHOW FULL PROCESSLIST"); while ($row=mysql_fetch_array($res)) { $pid=$row["Id"]; if ($row['Command']=='Sleep') { if ($row["Time"] > 3 ) { //any sleeping process more than 3 secs $sql="KILL $pid"; echo "\n$sql"; //added for log file mysql_query($sql); } } }
You can then save this to a file mysqlkillsleeping.php, and add it as a CRON job running every minute
vim /etc/crontab */1 * * * * root php /path/of/mysqlkillsleeping.php 2>&1 >> /var/log/mysqlsleep.log
No comments:
Post a Comment