PHP Scheduled task after closing the browser still continues to execute function _php Tutorial

Source: Internet
Author: User
Remember this function:
Function Name: Ignore_user_abort
Whether the PHP program continues to execute after this function has been configured or if the use End connection is interrupted. The default value stops when the connection is interrupted. The Ignore_user_abort option in the PHP configuration file (Php3.ini/php.ini) is the configuration section. This feature is only available after PHP version 3.0.7.
Official Note: http://cn2.php.net/manual/en/function.ignore-user-abort.php


How to use:
Copy CodeThe code is as follows:
Ignore_user_abort (TRUE); PHP scripts can continue to execute even if the client disconnects (such as turning off the browser).

This will enable you to achieve your scheduled tasks. However, the client access program is still the only line.
For example, in the generation of static pages, collection, there is no need to wait. Turn off your browser.
Example:
Copy CodeThe 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);
}

using the Ignore_user_abort function to implement PHP planning tasks
Copy CodeThe code is as follows:
Ignore_user_abort (TRUE);
Set_time_limit (0);
while (1) {
$fp = fopen (' Time_task.txt ', "A +");
$STR = Date ("y-m-d h:i:s"). " \n\r ";
Fwrite ($fp, $STR);
Fclose ($FP);
Sleep (5); Execute once in half an hour
}
?>

http://www.bkjia.com/PHPjc/322222.html www.bkjia.com true http://www.bkjia.com/PHPjc/322222.html techarticle Forget about this function: function name: Ignore_user_abort The PHP program will continue to execute after this function is configured or if the connection to the end of the use is interrupted. The default value is to stop after the connection is interrupted ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.