PDA

View Full Version : Killing MySQL process with PHP



nyx
24 Sep 2010, 09:01 AM
I'm looking for a method for killing a specific MySQL process with PHP.

The application allows users to potentially create very large queries to the database and I need to provide a method for them to kill / cancel the query if they wish.

I've seen a couple of examples of scripts which loop through the process list and kills processes which have been running for longer than a specified period, but I'm looking for something more specific.

Thanks in advance

Alan
24 Sep 2010, 10:50 PM
Only the operating system has ultimate control over processes. PHP has no power to intervene in MySQL processes unless it asks the operating system to do it (via a script) or MySQL allows it to, which it does. :)

MySQL provides SQL queries to view and kill processes. You can run these queries using PHP. This has it's limits as your database server could be choking, where running these queries may have no effect as they may never reach the database. :) At that point executing a script on the system may be an alternative option.

Have a look at the KILL syntax (http://dev.mysql.com/doc/refman/5.0/en/kill.html).