0

I have a PHP application that does lengthy processing operations on databases. Those operations are processed using AJAX calls. When an AJAX call is triggered, the UI becomes blocked using the JQuery BlockUI Plugin (http://malsup.com/jquery/block/). In the message appearing, I included a button to cancel the request/processing if it is taking too long. I want the following behaviour:

When the "Cancel" button is clicked, all active AJAX calls must be aborted. Then, since the PHP script called is still running on the server side, I will trigger another AJAX call to set a PHP session variable to false. In the PHP script, I am constantly checking for the value of this variable so that if it is false, then I exit() the current script.

Could anyone please give me insight on how I can possibly trigger the aborting of all AJAX calls on pressing a "Cancel" button? In addition, is there a way in a PHP script to launch a separate thread that constantly checks for a session variable's value and accordingly exits all running PHP scripts/functions or at least the current one?

Thanks in advance, Jeremie

jeremie_se
  • 380
  • 1
  • 2
  • 14

1 Answers1

1

You can cancel an ajax request with .abort(). As for terminating PHP when a request is cancelled, you could use ignore_user_abort.

You could make use of PHP workers to avoid letting users wait until PHP is done, google php workers. You'd find things like IronMQ and others, should be enough to get you going.

Community
  • 1
  • 1
Kevin Vandenborne
  • 1,397
  • 1
  • 10
  • 28
  • Thanks a lot for your quick reply! I will sure look at those PHP workers and ignore_user_abort in order to stop the PHP and avoid users from having to wait endlessly. – jeremie_se May 23 '14 at 13:30