0

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!

William Moore
  • 3,844
  • 3
  • 23
  • 41
  • It can be done,but it seems overkill to me. How many queries,what type of queries and so on would help.Maybe look at the logic before starting to kill processes. – Mihai Apr 05 '17 at 10:46

2 Answers2

0

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.

JvO
  • 3,036
  • 2
  • 17
  • 32
0

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.

Community
  • 1
  • 1