How to cancel a PHP process, when ajax call is cancelled?
Your server side php has to output something to detect the request is canceled. But as you are likely performing a lengthy sql query, you can't output anything.
But still you can save your connection id into a session, and kill the connection if it's detected:
- Open session
- Open sql connection
- If search_connection_id is set in session, kill the connection
- Find your connection id, save in session as search_connection_id
- Close the session - important, else the next request will be blocked in step 1
- Query database
- If connection is broken, it's another search killing you in step 3, exit
- Open session, remove search_connection_id
- Send response, close sql connection
Are you looking for ignore_user_abort() ?