PHP timed tasks, how to resolve

Source: Internet
Author: User
PHP timed Tasks
This post was last edited by hilives on 2014-02-26 18:18:21

Many novel sites have leaderboards, such as daily rankings, weekly rankings, such as this kind of leaderboards are 12 o'clock refresh at night,
Is this something done by hand or by a timed task?
If the use of timed tasks, is not using the following timing task method, solve



$interval =5;//Run every 5s

Method of Death Cycle
do{
echo ' Test '. Time (). '

Sleep ($interval);//Wait 5s
}while (TRUE);


------Solution--------------------
Linux under Crontab. Windows Scheduled Tasks. No need to die loops
------Solution--------------------
You don't have to use timed tasks to do it on your first visit every day

------Solution--------------------
Using the user click Execute php file, the leaderboard generated external files, and then use Filemtime () to determine

if (Time ()-filemtime ($file _name)) > 60*60*24) {
External file generation takes more than 24 hours, database operation, regenerate external files once
}
$file =file_get_contents ($file _name);

------Solution--------------------
Refresh the data when the user accesses it and determine if it is the time period to refresh the data
Data is collected when the user accesses it, and the cache data is updated to determine if the data is to be collected.
  • 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.