Randomly offset the update check schedule within $checkPeriod
This helps spread out update requests over all hours of the day and may prevent the update server from being hit with daily traffic spikes. See #323 for discussion.
This commit is contained in:
parent
908249c92e
commit
7014c9d9fd
|
|
@ -51,7 +51,14 @@ if ( !class_exists('Puc_v4p8_Scheduler', false) ):
|
|||
}
|
||||
|
||||
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
|
||||
wp_schedule_event(time(), $scheduleName, $this->cronHook);
|
||||
//Randomly offset the schedule to help prevent update server traffic spikes. Without this
|
||||
//most checks may happen during times of day when people are most likely to install new plugins.
|
||||
$firstCheckTime = time() - rand(0, max($this->checkPeriod * 3600 - 15 * 60, 1));
|
||||
$firstCheckTime = apply_filters(
|
||||
$this->updateChecker->getUniqueName('first_check_time'),
|
||||
$firstCheckTime
|
||||
);
|
||||
wp_schedule_event($firstCheckTime, $scheduleName, $this->cronHook);
|
||||
}
|
||||
add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue