Remember this function:
Function name: ignore_user_abort
This function configures or obtains whether the PHP program will continue to execute after the user connection is interrupted. The default value is to stop execution after disconnecting. The ignore_user_abort option in the PHP configuration file (php3.ini/php.ini) is the configuration location. This feature is only available after PHP version 3.0.7.
Official description: http://cn2.php.net/manual/en/function.ignore-user-abort.php
How to use:
Copy the code The code is as follows:
ignore_user_abort(true); //Even if the Client is disconnected (such as closing the browser), the PHP script can continue to execute.
Copy code The code is as follows:
//test
set_time_limit(0);
ignore_user_abort(true);
$i = 0;
while($i ++ < 200){
file_put_contents($i.'.php' , $i);
sleep(3);
}
Copy the code The code is as follows:
php
ignore_user_abort(true);
set_time_limit(0);
while(1) {
$fp = fopen('time_task.txt',"a+");
$str = date("Y-m-d h:i:s" )."nr";
fwrite($fp,$str);
fclose($fp);
sleep(5); //Execute once every half hour
}
?>
The above introduces the PHP scheduled task. The PHP scheduled task continues to execute functions after closing the browser, including the content of the PHP scheduled task. I hope it will be helpful to friends who are interested in PHP tutorials.