Can we use ignore_user_abort on any line of PHP like:
<?php
// Process Codes
if($_GET['nonstop']) {
ignore_user_abort(1);
// Background process
}else{
// Nonbackground process
}
// Other Codes
?>
Or we need to use on only after <?php (first line)?
Thanks.
You are able to use it anywhere you want within your code.
Die & Exit
ignore_user_abort() doesn’t disable die or exit. It just tells PHP (and the server) to NOT abort the script when the remote users’ connection closes.
Worth Noting
“PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush(). ” – PHP.Net