Anyway to Limit MySQL Query Execution time?

前端 未结 4 1925
旧时难觅i
旧时难觅i 2020-12-06 20:10

Hi I\'m having issues on my server at the minute because some of the MySQL queries are taking a very long time to run, and hogging the resources on the server.

I\'m

4条回答
  •  眼角桃花
    2020-12-06 20:43

    This is a purely php solution that seems to be the simplest solution from what I've managed to find so far.

    $result = mysql_query("SHOW FULL PROCESSLIST");
    while ($row=mysql_fetch_array($result)) 
    {
      $process_id = $row["Id"];
      if ($row["Time"] > 200 ) 
      {
        $sql="KILL {$process_id}";
        mysql_query($sql);
      }
    }
    

    And running this from a CRON script every 60 seconds.

    If anyone does find a better solution to this issue please let me know

提交回复
热议问题