Whether the Ignore_user_abort setting terminates the execution of the script if it disconnects from the client.
This function returns the previous value (a Boolean value) of the User-abort setting.
int Ignore_user_abort ([string $value])
Parameter setting Description: Optional. If set to true, the disconnect from the user is ignored and, if set to False, causes the script to stop running.
If this parameter is not set, the current setting is returned.
Note: PHP does not detect if the user is disconnected until an attempt is made to send the message to the client. Simply using the Echo statement cannot ensure that information is sent, see the flush () function.
Example-11 Ignore_user_abort () example, with the Set_time_limit () function and a dead loop can achieve the scheduled task function.
Copy Code code as follows:
<?php
Ignore_user_abort (TRUE);
Set_time_limit (0);
Echo ' Testing connection handling in PHP ';
while (1)
{
if (Connection_status ()!= connection_normal) {
Break
}
Sleep for ten seconds
Sleep (10);
}
?>
PHP built-in function Research Series Phase II, the use of PHP functions Ignore_user_abort implementation of planning tasks and continuous process instances, and through an example of a detectable effect of ignore_user_abort () function and usage.
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.
Attached: Another introduction
One, function prototype
Copy Code code as follows:
int Ignore_user_abort ([bool setting])
Two, version compatible
Copy Code code as follows:
PHP 3 >= 3.0.7, PHP 4, PHP 5
The basic usage and example of function
1, function base usage
Copy Code code as follows:
<?php
Ignore_user_abort ();
?>
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
Copy Code code as follows:
<?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
Copy Code code as follows:
<?php
Ignore_user_abort (TRUE);
Set_time_limit (0);
$interval = 10;
$stop = 1;
do {
if ($stop = =) break;
File_put_contents (' liuhui.php ', ' Current time: '. Time (). Stop: '. $stop);
$stop + +;
Sleep ($interval);
} while (true);
?>
Open the liuhui.php file with the following contents:
Copy Code code as follows:
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. For more information, please participate in the PHP manual. Please pay attention to the next issue of the PHP built-in function research series.