Scheduled (scheduled) tasks implemented by PHP

Source: Internet
Author: User
Sometimes in order to adjust the interface periodically, the program needs to run automatically. 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.
  1. PHP scripts can continue to execute even if the client disconnects (such as turning off the browser).
  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 = "Http://www.xxx.con";
  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
Php
  • 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.