note 22167 added to ref.mysql
| From: | vinod at jobsure dot com | Date: | Sun, 09 Jun 2002 06:22:18 +0000 |
| Subject: | note 22167 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31617@lists.php.net to get a copy of this message | ||
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
//###################//
--
http://www.php.net/manual/en/ref.mysql.php
http://master.php.net/manage/user-notes.php?action=edit+22167
http://master.php.net/manage/user-notes.php?action=delete+22167
http://master.php.net/manage/user-notes.php?action=reject+22167