Implementation of php scheduled tasks

Source: Internet
Author: User

Recently, because the project needs to regularly process the remote database, a scheduled task is needed here. After hard work, php was finally used to implement this planned task. The following describes the implementation process.

This php implementation mainly uses the ignore_user_abort () set_time_limit (0) sleep () functions.

The specific code is as follows:

<? Phpignore_user_abort (); // This function is used to execute PHP scripts when the user closes the browser. set_time_limit (3000); // use set_time_limit (0) to allow unlimited execution of the program $ interval = 5; // run every 5s // method 1 -- endless loop do {echo 'test '. time (). '<br/>'; sleep ($ interval); // wait for 5 s} while (true); // method 2 --- periodically execute require_once 'in sleep '. /curlClass. php '; // introduce the file $ curl = new httpCurl ('www .phpernote.com'); // instantiate $ stime = $ curl-> getmicrotime (); for ($ I = 0; $ I <= 10; $ I ++) {echo 'test '. time (). '<br/>'; sleep ($ interval); // wait for 5 s} ob_flush (); flush (); $ etime = $ curl-> getmicrotime (); echo '

In the specific implementation process, I personally feel that PHP's scheduled task execution efficiency is not high. I suggest you hand over the scheduled task execution to shell. Relatively speaking, this method is too hard to implement, while shell is professional.

Articles you may be interested in
  • Settings of win7 scheduled tasks
  • How to accurately count the number of online users using php
  • PHP records search engine paths and keywords
  • PHP is the safest and most practical solution to determine the type of uploaded files
  • What is the php design pattern and how to understand it?
  • PHP analyzes the file header information to determine the type of the uploaded file
  • Php retrieves the last day of any month
  • Underlying operating mechanism and principle of 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.