The Ignore_user_abort setting terminates execution of the script with the client.
This function returns the previous value of the User-abort setting (a Boolean value).
int Ignore_user_abort ([string $value])
| Parameters |
Describe |
| Setting |
Optional. If set to true, disconnecting from the user is ignored and setting to false causes the script to stop running. If this parameter is not set, the current setting is returned.
|
Note: PHP does not detect whether a user has been disconnected until an attempt is made to send a message to the client. Simply use the ECHO statement to not ensure that information is sent, see the flush () function.
| 1234567891011121314151617181920212223242526 |
例-1 一个的ignore_user_abort()的例子,配合set_time_limit()函数 和一个死循环就可以实现计划任务功能。 <?php // Ignore user aborts and allow the script // to run forever ignore_user_abort (true); set_time_limit (0); echo ‘Testing connection handling in PHP‘; // Run a pointless loop that sometime // hopefully will make us click away from // page or click the "Stop" button. while(1) { // Did the connection fail? if( connection_status () != CONNECTION_NORMAL ) { break; } // Sleep for 10 seconds sleep (10); } // If this is reached, then the ‘break‘ // was triggered from inside the while loop // So here we can log, or perform any other tasks // we need without actually being dependent on the // browser. ?> |
PHP built-in function research series in the second phase, the PHP function Ignore_user_abort is used to implement the scheduled task and the continuous process instance, and discusses the function and usage of the ignore_user_abort () function through an example of the detectable effect.
Ignore_user_abort () can be implemented when the client shuts down can still execute PHP code, can keep the PHP process has been executing, can achieve so-called scheduled task function and continuous process, only need to open the execution script, unless the Apache and other server restart or have script output, This PHP script will always be in the state of execution, but at the cost of a PHP execution of the script's ongoing process, the cost is large, but can achieve a lot of unexpected features.
It is described as setting whether or not the client disconnects the execution of the script.
One, function prototypes
| 1 |
intignore_user_abort ( [boolsetting] ) |
Two, version compatible
PHP 3 >= 3.0.7, PHP 4, PHP 5
third, function base usage and example
1, function base usage
| 123 |
<?phpignore_user_abort();?> |
Description: Calling the Ignore_user_abort () function declares that the execution of the script is not terminated even if the client disconnects.
2, combined with set_time_limit () function to implement a cyclic script execution task
| 12345678 |
<?phpignore_user_abort();set_time_limit(0);$interval=60*15;do{//执行的业务}while(true);?> |
Description: Loop execution every 15 minutes
3, custom implement file output and trace the execution result of Ignore_user_abort () function
| 123456789101112 |
<?phpignore_user_abort ( TRUE );set_time_limit ( 0 );$interval = 10;$stop = 1;do{ if( $stop == 10 ) break; file_put_contents(‘liuhui.php‘,‘ Current Time: ‘.time().‘ Stop: ‘.$stop); $stop++; sleep ( $interval );} while( true);?> |
Opens the liuhui.php file with the following file contents:
Current time:1273735029 Stop:9
The principle is that even if the client terminates the script, it is still executed every 10 seconds and prints out the current time and end point, so that the Ignore_user_abort () function can be tested.
It is very useful to find the ignore_user_abort () function through an example, to realize the task of planning, to complete the follow-up task, and to continue the process. Please participate in the PHP manual for more instructions. Take a look at the next series of PHP built-in function studies.
PHP function Ignore_user_abort ()