Enforce update frequency settings ($checkPeriod) even when triggered by a cron event.

The WordPress cron implementation does not guarantee that a cron hook will only be run once, or run exactly on schedule. For example, it's possible for an event to be triggered two or three times in quick succession due to race conditions. If we check for updates each time our hook is run, we could end up sending redundant update requests that waste bandwidth and server resources.

Instead, make sure at least $checkPeriod hours have elapsed since the last check before checking again. Allow for a small fuzz-factor (currently 20 minutes) to account for the inherent inaccuracy of WP cron.
This commit is contained in:
Yahnis Elsts 2013-12-03 01:40:44 -08:00
parent d921ed91e8
commit 89da7ab52d
1 changed files with 4 additions and 4 deletions

View File

@ -345,10 +345,10 @@ class PluginUpdateChecker_1_4 {
//Check less frequently if it's already known that an update is available.
$timeout = $this->throttledCheckPeriod * 3600;
} else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
//Check every time if triggered by cron and throttling is disabled. Our cron event is
//scheduled to run every $checkPeriod hours, so we don't need to check how much time
//has passed since the last check.
$timeout = 0;
//WordPress cron schedules are not exact, so lets do a n update check even
//if slightly less than $checkPeriod hours have elapsed since the last check.
$cronFuzziness = 20 * 60;
$timeout = $this->checkPeriod * 3600 - $cronFuzziness;
} else {
$timeout = $this->checkPeriod * 3600;
}