kill_all_queries.php 847 B

12345678910111213141516171819202122
  1. <?php
  2. /**
  3. * This script kills all queries to which the Chamilo database user has access
  4. * through processlist.
  5. * Use only when you have an impossible situation with an urgent need to
  6. * restart or stop the database, and it just won't stop because it want to
  7. * finish queries first, and these queries are waiting for a lock on a table
  8. * that seems to never free itself.
  9. * In this case, disable the exit(); line below, run this script and then you
  10. * should be able to quickly restart your database.
  11. */
  12. exit;
  13. require_once '../../main/inc/global.inc.php';
  14. $result = Database::query("SHOW FULL PROCESSLIST");
  15. while ($row=Database::fetch_array($result)) {
  16. $process_id=$row["Id"];
  17. if ($row["Time"] > 200 ) {
  18. $sql="KILL $process_id";
  19. Database::query($sql);
  20. }
  21. }
  22. echo "All queries by this user have been killed".PHP_EOL;