The Ignore_user_abort function in PHP is that when the user turns off the terminal and the rear foot is still executing, it can be used to implement the scheduled task and the ongoing process, and the following example discusses the function and usage of the Ignore_user_abort () function.
Ignore_user_abort () can be implemented when the client is still able to execute PHP code after shutdown, you can keep the PHP process is always executing, you can achieve the so-called scheduled tasks and continuous process, only need to open the execution script, unless Apache and other servers restart or have script output, The PHP script will always be in the state of execution, at first glance very practical, but the price is a PHP execution script continuous process, expensive, but can achieve a lot of unexpected features.
It is described as whether setting up a disconnect from the client will terminate the execution of the script.
One, function prototype
int Ignore_user_abort ([bool setting])
Second, version compatible
PHP 3 >= 3.0.7, PHP 4, PHP 5
The basic usage and example of function
1, function base usage
Description: Invokes the Ignore_user_abort () function to declare that the execution of the script is not terminated even if the client disconnects.
2, combining the Set_time_limit () function to implement a cyclic script execution task
<?php
Ignore_user_abort ();
Set_time_limit (0);
$interval =60*15;
do{
The business performed
}while (TRUE);
?>
Description: Circular execution every 15 minutes
3, customizing the implementation of the file output and tracking the execution results of the ignore_user_abort () function
<?php
Gnore_user_abort (TRUE);
Set_time_limit (0);
$interval = 10;
$stop = 1;
do {
if ($stop = =) break;
File_put_contents (' viphper.php ', ' Current time: '. Time (). ' Stop: '. $stop);
$stop + +;
Sleep ($interval);
} while (true);
?>
Open the viphper.php file with the following contents:
Current time:1273735029 Stop:9
The idea is that even if the client terminates the script, it still executes every 10 seconds and prints out the current time and end point so that the Ignore_user_abort () function can be tested.
It is found that the Ignore_user_abort () function is very practical, realizes the planning task, completes the follow-up task, and the continuous process is very effective.