Kill MySQL query on user abort

后端 未结 6 1441
星月不相逢
星月不相逢 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:06

    Once PHP notices the user has stopped the request (this usually will not happen until the script tries to output something to the user), your script will terminate. Before shutting down, PHP calls any shutdown functions you've activated. You can implement a shutdown function that kills your query, and register it with register_shutdown_function()

    An other way you might be able to do this, is by running your script with ignore_user_abort() turned on, and checking if the user has aborted by calling connection_aborted() periodically. If the user has aborted, kill the query and gracefully exit your script.

    More information on connection handling here.

提交回复
热议问题