Kill MySQL query on user abort

后端 未结 6 1443
星月不相逢
星月不相逢 2020-12-05 03:30

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

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 04:04

    i think you can give a try to mysql KILL

    http://dev.mysql.com/doc/refman/5.0/en/kill.html

    if you are able to call something over user abort then you can use KILL to kill you mysql connection or query by fetching it's process id.

    And as you said in your comment that PHP is blocked until mysql returns

    so you can take help from javascript in this way:

    1.detect the user abort using JS 2.call a function on user abort 3.in that function you can kill you previous query but here you need the process id of the previous query so you can get that by a trick that you can select the process id when you run you first long query and pass it to JS function and use it in killing you query.

    Hope it will help you.

提交回复
热议问题