KILL MySQL requests PHP if the user closes the browser or moves from one page to another page

My site uses onload AJAX. Therefore, when a user entering AJAX calls on page 6 is executed in parallel. In the middle of the process, if the user closes the browser or moves to another page, I want to kill requests.

Steps to achieve this:

1. Locate the following MySQL query execution identifier (connection identifier) ​​and save it in the session.

http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html

We need to identify this identifier before executing a READ (select) request. Because PHP will run line by line.

Problem

How do we identify the next connection identifier?

OR

 How do we reserve the connection identifier and execute the query on specified identifier? 

2 . Run the query in the database.

3. If the user is interrupted, then destroy the execution of the MySQL query. We can detect user aborted status in PHP using the connection_aborted () / ignore_user_abort () function.

Use this following command to complete this request:

KILL ID

+7
performance php mysql mysqli
source share
2 answers

The following query also returns the current connection identifier

 SELECT CONNECTION_ID(); 

After receiving this connection identifier, we can fulfill our request using this identifier.

+1
source share

Step 1: Get MySql Connection Flow Identifier

  $thread_id = mysqli_thread_id($link); 

Step 2: Use ignore_user_abort (); in code

Step 3: Check if the connection is closed. If so, destroy the stream as follows:

  if (connection_aborted() && mysqli_kill($connection_link, $thread_id)) { die(); } 

Check the accepted solution to this issue .

+3
source share

All Articles