Question

I wrote a script that has no time limit and max_execution_time is 0

  1. I should work until the end of it's job or on User abort (canceling from browser).
    How can I be sure when user aborts page load from browser the script is killed by server?

  2. Does this kills script immediately or __destructor of classes are called before?

Was it helpful?

Solution

Assuming this is called by ajax, you could add a event handler for when the user leaves the webpage that sends an ajax request that is handled by a script that kills the other script.

This could be implemented by having the script create a file when it starts. Then, every one and a while it checks to see if that file is still there. If it is it continues if not it quits.

The trick is finding the filename. The way I do this is give every page request a unique user ID. And both the 'worker' script and the 'kill' script are called with the same user ID in the url (GET).

OTHER TIPS

To my understanding there is no way with php to stop script execution when a user aborts the page load on their end. I am assuming by "Aborting" you mean clicking stop or closing the browser while the page is still loading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top