Reputation: 8071
I have a script that takes quite a long time to execute. Is there a way to run some code or call a function in case for example the user closes the window while the script is still running? Ideally I would like to run code to set a status as failure in the database.
Upvotes: 1
Views: 78
Reputation: 2232
You can divide the processing in small parts, for example process.php?part=1,2,3 and so on. But you have to save the state of last processing progress in some place safe to access it next time script executes and continues from where it ended. I cannot say much cause your question need to be more specific.
Upvotes: 0
Reputation: 97835
See ignore_user_abort
and connection_status
.
Note, however, that you may only be able to detect the client has disconnected when you're sending data. So if you're using output buffering, you may only detect it after the script has executed.
Upvotes: 2