我有一个大型查询,我想在用户中止后立即终止。我搜索过并发现了以下问题:
从这些问题中我减去了导致下面代码的有用部分。
// Connection to query on
$query_con = mysqli_connect($host, $user, $password, $name);
// Connection to kill on
$kill_con = mysqli_connect($host, $user, $password, $name);
$slow_query = "...";
// Start the query
$query_con->query($slow_query, MYSQLI_ASYNC);
// Get the PID
$thread_id = $query_con->thread_id;
// Ignore user abort so we can kill the query
ignore_user_abort(true);
do {
// Poll MySQL
$links = $errors = $reject = array($mysqli->mysqli);
$poll = mysqli_poll($links, $errors, $reject, 0, 500000);
// Check if the connection is aborted and the query was killed
if (connection_aborted() && mysqli_kill($kill_con, $thread_id)) {
die();
}
} while (!$poll);
// Not aborted, so do stuff with the result
$result = $link->reap_async_query();
if (is_object($result)) {
// Select
while ($row = $result->fetch_object()) {
$articles[] = $row;
}
}
echo count($articles);
上面的代码引发了以下错误:
我真的被困在这里,不知道如何从这一点开始。