laravel取消数据库查询

I have a site in laravel where a single page makes multiple database queries (select statements which can take a little while to run).

Is there a way to detect if a user:

  • Refreshes the page
  • Changes the parameters of the query
  • Closes the page

hence meaning that the result of the query is not needed, and therefore cancelling it or killing the process?

Note the database is mysql so I can from mysql workbench easily call kill {PID} to end a similar query manually.

Thanks!

Yest, this can all be detected easily with some JavaScript; there is an 'onunload' event that is fired when the user tries to leave or close the page, so that answers 1 and 3. Changing a field in a form is also easy to detect.

The hard problem will be to match the cancel request with the original query; somehow you have to know the PID of that query, and since MySQL functions generally don't return until they are done you can't ask for information like the PID.

You can detect if a user leaves or reloads a page with Javascript, catching the ONUNLOAD event (documentation here, SO related question here).
To check if query parameters change, you should specify if the user enters them manually in a form or any other way you are getting them, there's a different answer for any different method.