Kill MySQL process in PHP

0
82
MySQL

This tutorial explains how to kill MySQL processes in PHP.

You can filter the database user, sleep queries and dead processes.

$connect = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
	
if($connect->connect_error)
die("Unable to Connect to ".DB_HOST." : ".$connect->connect_error);

$result_kill = $connect->query("SHOW FULL PROCESSLIST");
if($result_kill->num_rows > 0){
while ($row=$result_kill->fetch_assoc()) {
  $process_id=$row["Id"];
   $command=$row["Command"];
   $user=$row["User"];
  if ($row["Time"] > 100 &&  $user=='dbuser') {
    $sql_kill="KILL $process_id";
    $connect->query($sql_kill);
  }
}
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here