본문 바로가기
DataBase/MySQL

Sleep process 죽이기

by 백룡화검 2010. 4. 24.

<?
    define("MAX_SLEEP_TIME", 1800);

    $hostname = "localhost";
    $username = "id";
    $password = "pwd";

    $connect = mysql_connect($hostname, $username, $password);
    $result = mysql_query("SHOW PROCESSLIST", $connect);
    while($proc = mysql_fetch_assoc($result)) {
        if($proc["Command"]== "Sleep" && (int)$proc["Time"] > MAX_SLEEP_TIME) {
            @mysql_query("KILL ".$proc["Id"], $connect);
        }
    }
    mysql_close($connect);
?>