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.