note 22167 deleted from ref.mysql by aidan
| From: | aidan@php.net | Date: | Sun, 15 Aug 2004 11:06:36 +0000 |
| Subject: | note 22167 deleted from ref.mysql by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74689@lists.php.net to get a copy of this message | ||
Note Submitter: vinod at jobsure dot com
----
To protect your mysql server from long running query which hangs the database
This PHP code basically kills the long running sql process .
I kept this PHP file in cron to run every 15 minues and believe me
it had dramatic performance on my website and my mysql database NEVER HANGED
//################ //
kill_long_query.php
//################ //
set_time_limit(30000);
$result=mysql_query("show processlist");
while ($row=mysql_fetch_array($result))
{
$process_id=$row["Id"];
if (($row["Time"] > 100 ) || ($row["Command"]=="Sleep") )
{
print $row["Id"];
$sql="kill $process_id";
mysql_query($sql);
}
}
//###################//
http://www.db-forums.com/viewtopic.php?t=8
//###################//