Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
ignore_user_abort() function in PHP
The ignore_user_abort() function sets whether a remote client can abort the running of a script. When enabled, the script continues executing even if the user closes their browser or navigates away from the page.
Syntax
ignore_user_abort(setting)
Parameters
setting − Optional boolean parameter.
TRUEignores user aborts (script continues running),FALSEallows user aborts to stop the script (default behavior).
Return Value
The ignore_user_abort() function returns the previous value of the user-abort setting as an integer (0 for false, 1 for true).
Example 1: Getting Current Setting
The following example gets the current ignore_user_abort setting ?
<?php
$current_setting = ignore_user_abort();
echo "Current ignore_user_abort setting: " . $current_setting;
?>
Current ignore_user_abort setting: 0
Example 2: Enabling User Abort Ignore
This example enables ignore_user_abort and shows the previous setting ?
<?php
$previous_setting = ignore_user_abort(true);
echo "Previous setting: " . $previous_setting . "<br>";
echo "Current setting: " . ignore_user_abort();
?>
Previous setting: 0 Current setting: 1
Practical Use Case
This function is commonly used for long-running processes that should complete even if the user disconnects ?
<?php
// Enable ignore user abort for critical file processing
ignore_user_abort(true);
// Process large file that might take several minutes
$large_file = file_get_contents('huge_data.txt');
// Process and save results - continues even if user leaves page
$processed_data = process_data($large_file);
file_put_contents('results.txt', $processed_data);
// Restore original setting
ignore_user_abort(false);
?>
Conclusion
The ignore_user_abort() function is useful for ensuring critical scripts complete execution even when users disconnect. Always restore the original setting after completing long-running operations.
