How to implement a scheduled (scheduled) task for PHP

Source: Internet
Author: User
    Sometimes it is necessary for the program to run automatically in order to adjust the interface periodically. There are two ways to do this from the Internet: 1, Ignore_user_abort () Ignore_user_abort () functions with Set_time_limit (0) and sleep ($interval) can be implemented to automatically run updates. Example: (As long as you run the following page, the browser shutdown program will always run)
  1. //Even if the client disconnects (such as turning off the browser), the PHP script can also Continue to execute.
  2. Ignore_user_abort ();
  3. //Execution time is unlimited, php default execution time is 30 seconds, through Set_time_limit (0) can allow the program to execute indefinitely
  4. set_time_limit (0);
  5. //Run every 5 minutes
  6. $interval =60*5;
  7. do{
  8. $url = "";
  9. $ch = Curl_init ();
  10. curl_setopt ($ch, Curlopt_url, $url);
  11. curl_setopt ($ch, Curlopt_returntransfer, 1);
  12. curl_setopt ($ch, Curlopt_timeout, 2);
  13. $result = curl_exec ($ch);
  14. curl_close ($ch);
  15. //wait 5 minutes
  16. sleep ($interval);
  17. }while (true);
copy code
  • 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: 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.