if user posts to server and it begin a processing, sending nothing to user while doing so (it might take a few seconds, eg, sending mail through outside service) and user goes to another site or page before it finishes
is server notified?
when does server give up?
does server try to finish processing?
is there any way to make a function “atomic” in php so that, once begun, it is guaranteed to finish?
Default and right behaviour of the user client browser is that it SHOULD notify that page loading has been cancelled – reasons don’t matter – user either pressed back button, stop button, clicked another link or just closed the browser.
By default in PHP – server receives this notice and quits processing page. This depends on setting of php.ini directive
ignore_user_abort– see this PHP documentation page.Server behaves upon setting of
ignore_user_abortdirective. If it is set to false (default), than it just stops processing the request. If it is set true, then it finishes request as it wouldn’t receive any notice about user abort.It is not advised to run with
ignore_user_abort = trueserver-wide, so I wouldn’t recommend you to put it directly in php.ini file. But you could put this code at the beginning of the script which is cruical for you to be atomic and to always finish when started: