When running a long query from PHP, [how] can I kill the query if the user presses stop in their browser?
Take into consideration that I cannot call
This is an example of doing it with PDO.
$id = $connection->executeQuery("SELECT CONNECTION_ID()")->fetchColumn();
ignore_user_abort(true);
while($row = $result->fetch()) {
/* Processing ... */
if (connection_aborted()) {
$this->connection->executeQuery("KILL CONNECTION $id");
break;
}
}
Note: Keep an eye out for multiple connections, you may kill the wrong one.