PHP ignore_user_abort() Function
The PHP ignore_user_abort() function sets whether a client disconnect should cause a script to be aborted.
When running PHP as a command line script, and the script's tty goes away without the script being terminated then the script will die the next time it tries to write anything, unless enable is set to true.
Syntax
ignore_user_abort(enable)
Parameters
enable |
Optional. If set and not null, this function will set the ignore_user_abort ini setting to the given enable. Otherwise, this function will only return the previous setting without changing it. |
Return Value
Returns the previous setting, as an integer.
Example: ignore_user_abort() example
The example below shows how to use ignore_user_abort() function.
<?php //ignoring user aborts and allowing //the script to run forever ignore_user_abort(true); set_time_limit(0); echo 'Testing connection handling in PHP'; while(1) { //if this is reached, then the //'break' will be triggered //here we can log, or perform any //other tasks we need without actually //being dependent on the browser if(connection_status() != CONNECTION_NORMAL) { break; } //sleep for 2 seconds sleep(2); } ?>
The output of the above code will be:
Testing connection handling in PHP
❮ PHP Miscellaneous Reference