PHP / Ajax cancel a process running in a for-each loop
Posted on 2010-01-05
I have a PHP process which, when started iterates through a bunch of orders in a MySQL table using for-each, and calls a SOAP function to update the order from a remote server.
The process could take a few minutes, so I send updates to the browser using Ajax Prototype.Updater. I need a way for the user to cancel the process mid-run.
I though about creating a session variable on a submit button, and in each run of the for-each loop checking if the session had been set, but it seems that updates from the browser, inlcuding pressing the cancel button, are only sent after the process has completed, which is too late!
What's the best way of doing this?