PHP Execution After Client Disconnection

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

After a bunch of digging around and some help from the nice people on the #php channel on freenode IRC, I have cleared up the issue regarding PHP script execution and client connection.

If a client disconnects (closes the browser window / tab) and PHP subsequently tries to send information to the client but fails, the script stops executing.

Echoing does not necessarily mean sending information as PHP uses an output buffer. If you use the flush() function though you can force the buffer to be flushed to the client.

If you want to be sure a script will continue to execute when a client has disconnected, you can use the ignore_user_abort() function which will do exactly that.

Problem Solved :-)

Tags: phpexecutionflushabortclientdisconnect