执行与PHP和AJAX过程中杀死了MySQL查询过程中、杀死了、PHP、AJAX

2023-09-10 14:42:52 作者:微笑面對未來

我创建一个自定义查询生成器,当用户已经创建了他的问题,他可以通过点击一个按钮,验证查询语法。当在按钮上点击用户进行验证,一种AJAX调用与一个取消按钮向服务器发送与查询起动的查询和执行,此时用户中可以看到一个模态他的屏幕上。万一用户点击取消按钮,我希望再派AJAX调用服务器杀查询的执行。

I am creating a custom query builder, when user has created his query he can verify the query syntax by clicking a button. When the user click on the button to verify, An AJAX call is sent to the server with the query and execution of the query starts, during this time user can see a modal on his screen with a cancel button. If by any chance user clicks on the cancel button I want the send another AJAX call to the server to kill the execution of the query.

目前我只能够杀死AJAX调用我原本发送和我的网页能正常工作,在用户端

Currently I am only able to kill the AJAX call which I originally send and my page works fine at user end

但我在寻找一个PHP code停止在服务器端的MySQL查询,因为一些查询可以非常的重,运行时间长

but I am looking for a PHP code to stop the MYSQL query at server side because some queries can be quite heavy and run for a long time

推荐答案

首先,如果查询的目的只是为了检查语法,不执行它!执行解释,或添加限制0,或对空数据库执行。

First of all, if the purpose of the query is just to check the syntax, do not execute it! execute explain, or add limit 0, or execute against empty database.

至于杀害,您必须连接到数据库root权限的,并发出KILL命令(但你需要知道查询ID)。或者你可以杀死所有的线程。看看到的mysqli ::杀

As for the killing, you have to connect to database with root privileges, and issue KILL command (but you need to know the query id). Or you can kill the entire thread. Take a look to mysqli::kill

编辑:看来你并不需要root权限,由用户看的查询,使用SHOW PROCESSLIST命令

seems you don't need root privileges, to see queries by your user, use SHOW PROCESSLIST command