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