Learn how PHP timing tasks are implemented

Source: Internet
Author: User
    1. Ignore_user_abort (); PHP scripts can continue to execute even if the client disconnects (such as turning off the browser).
    2. Set_time_limit (0); Execution time is unlimited, php default execution time is 30 seconds, through Set_time_limit (0) can allow the program to execute indefinitely
    3. $interval =60*5; Run every 5 minutes
    4. do{
    5. $fp = fopen (' test.txt ', ' a ');
    6. Fwrite ($fp, ' test ');
    7. Fclose ($FP);
    8. Sleep ($interval); Wait 5 minutes
    9. }while (TRUE);
    10. ?>
Copy Code

Just run the page above and then turn it off, and the program will run all the way down.

There are simpler crontab commands in Linux.

The function of the crontab command is to schedule execution of some commands at certain intervals.

Crontab How to use: crontab [-e |-l |-r] FileName-E: Edit Task-L: Show task Information-r: Delete scheduled execution task information

CRONTAB Format: * * * * * * command time, day and month to run commands

Examples of crontab:

    1. */5 * * * * Lynx http://bbs.it-home.org

    2. Access once every 5 minutes bbs.it-home.org

    3. 0 8 * * * Lynx http://bbs.it-home.org

    4. 8 visits to bbs.it-home.org every morning.

    5. 0 6 * 1-5 Lynx http://bbs.it-home.org

    6. 6th on each month and 10 in the morning of Monday to Friday of each week visit bbs.it-home.org

    7. 0 5 7 8 * Lynx http://bbs.it-home.org

    8. August 7 Morning 5 Visit bbs.it-home.org

Copy Code

Explanation: "*" stands for all values within the range of numbers, "/" stands for each meaning, "*/5" represents every 5 units, "-" represents a number from one digit to a number, "," separates several discrete numbers.

This article transferred from: HTTP://HI.BAIDU.COM/ANDYLU1988/ITEM/9674D31406ED61008EBDE4B6

  • 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.