如果用户关闭浏览器或从一页导航到另一页,则使用PHP杀死MySQL查询 [英] KILL MySQL queries using PHP if user close the browser or navigate from one page to other page

查看:65
本文介绍了如果用户关闭浏览器或从一页导航到另一页,则使用PHP杀死MySQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站正在使用onload AJAX.因此,当用户进入页面时,将并行执行6个AJAX调用.在此过程的中间,如果用户关闭浏览器或导航到另一个页面,我想终止查询.

My website is using onload AJAX. So when the user entering into a page 6 AJAX calls are executed parallel. In middle of the process if user close the browser or navigate to another page I wants to kill the queries.

实现此目标的步骤:

1..找到下一个MySQL查询执行ID(连接标识符)并将其存储到会话中.

1. Find the Next MySQL query execution ID(The connection identifier) and store it into a session.

http://dev.mysql.com/doc/refman/5.1/en /show-processlist.html

在执行READ(select)查询之前,我们需要标识此ID.因为PHP将逐行执行.

We need to identify this ID before execute the READ(select) query. Because PHP will execute line by line.

问题

How do we identify the next connection identifier?

How do we reserve the connection identifier and execute the query on specified identifier?

2 .在数据库中执行查询.

2. Execute the query in database.

3..如果确定用户已中止,则终止MySQL查询执行.我们可以使用connection_aborted()/ignore_user_abort()函数检测PHP中的用户中止状态.

3. If user aborted is identified then kill the MySQL query execution. We can detect the user aborted status in PHP using connection_aborted()/ ignore_user_abort() function.

使用以下命令终止此查询执行:

Use this following command to terminate this query execution:

KILL ID

推荐答案

以下查询还返回当前的连接标识符

The following query also returns the current connection identifier

SELECT CONNECTION_ID();

收到此连接标识符后,我们可以对该标识符执行查询.

After receiving this connection identifier we can execute our query on this identifier.

这篇关于如果用户关闭浏览器或从一页导航到另一页,则使用PHP杀死MySQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆