mysql_kill_proc function

Post bugs or suggestions to the game here. Or discuss development topics.
Post Reply
Turock
Forum Maniac
Posts: 289
Joined: Sat Jan 07, 2006 12:45 am
Contact:

Post by Turock »

Just a little something I though might help Slashers hanging SQL processes.

code: Select all

function mysql_kill_proc($timeout) {
    if($timeout == "") $timeout = 60;  // might need to change this 
    $result = mysql_query("SHOW FULL PROCESSLIST");
    while ($row = mysql_fetch_assoc($result)){
        if($row["Time"] > $timeout AND $row["Command"] == "Sleep" AND $row["Info"] == "" AND $row["db"] <> ""){
            mysql_query("KILL ".$row["Id"]);
        }
    }
    mysql_free_result($result);
}
Note that I have not tested this but it SHOULD work. :P

I couldn't get some SQL processes to hang on purpose so thats why its not tested. Also I would try what Beatles suggested first, adding mysql_close(); to theend.php as this might be considered more of a bandaid than a solution.
User avatar
Slasher
The FAF Forums SMEGHEAD!!! lol
Posts: 2635
Joined: Mon May 03, 2004 5:08 pm
Location: http://florida4us.com/
Contact:

Post by Slasher »

If you like I can PM you my cPanel info and oyu can have a mess around and see if you can stop hanging and all that if this mysql_close(); doesn't work.
I do not have a signature, you must be imagining

http://florida4us.com/

Image
User avatar
Slasher
The FAF Forums SMEGHEAD!!! lol
Posts: 2635
Joined: Mon May 03, 2004 5:08 pm
Location: http://florida4us.com/
Contact:

Post by Slasher »

The close thingy didnt work either where do I put this?
I do not have a signature, you must be imagining

http://florida4us.com/

Image
User avatar
The Beatles
Fear me for I am root
Posts: 6285
Joined: Tue May 24, 2005 8:12 pm

Post by The Beatles »

Put it, say, in a file called mkp.php, and make it include config.php. Best if you DON'T put it in a webserver-accessible location. Then run it every 5 minutes via cron.

Oh, add a line below that actually calling the function, e.g. mysql_kill_proc().

Thanks turock!
:wq
Post Reply
  • Members connected in real time

    🔒 Close the panel of connected members