title: Kill MySQL query on user abort
body: <p>When running a long query from PHP, <strong>[how] can I kill the query if the user presses stop in their browser?</strong></p>
  
  <p>Take into consideration that I cannot call any other PHP functions because PHP is blocked while waiting for MySQL.</p>
  
  <p>Also I cannot make any more requests to the server (via Ajax) because of session locking.</p>
  
  <p>So one solution could be: </p>
  
  <ul>
  <li>ignore user abort</li>
  <li>run the long query in the back ground and have PHP check every 100ms if it has finished</li>
  <li>get the pid from the query</li>
  <li>if the user aborts, kill the pid</li>
  <li>else return the result when finished</li>
  </ul>
  
  <p>The 2 thing that I dont know how to do in that is:</p>
  
  <ul>
  <li>run a non blocking (background) query </li>
  <li>get the pid of a query</li>
  </ul>