diff options
Diffstat (limited to 'core/UpdateCheck.php')
-rw-r--r-- | core/UpdateCheck.php | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php index c5ebe07874..8e7b09b581 100644 --- a/core/UpdateCheck.php +++ b/core/UpdateCheck.php @@ -17,7 +17,7 @@ */ class Piwik_UpdateCheck { - const CHECK_INTERVAL = 86400; + const CHECK_INTERVAL = 28800; // every 8 hours const LAST_TIME_CHECKED = 'UpdateCheck_LastTimeChecked'; const LATEST_VERSION = 'UpdateCheck_LatestVersion'; const PIWIK_HOST = 'http://api.piwik.org/1.0/getLatestVersion/'; @@ -25,29 +25,34 @@ class Piwik_UpdateCheck /** * Check for a newer version + * + * @param bool $force Force check */ - public static function check() + public static function check($force = false) { $lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED); - if($lastTimeChecked === false + if($force || $lastTimeChecked === false || time() - self::CHECK_INTERVAL > $lastTimeChecked ) { + // set the time checked first, so that parallel Piwik requests don't all trigger the http requests + Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1); $parameters = array( 'piwik_version' => Piwik_Version::VERSION, 'php_version' => phpversion(), 'url' => Piwik_Url::getCurrentUrlWithoutQueryString(), 'trigger' => Piwik_Common::getRequestVar('module','','string'), + 'timezone' => Piwik_SitesManager_API::getInstance()->getDefaultTimezone(), ); $url = self::PIWIK_HOST . "?" . http_build_query($parameters, '', '&'); $timeout = self::SOCKET_TIMEOUT; try { - $latestVersion = Piwik::sendHttpRequest($url, $timeout); + $latestVersion = Piwik_Http::sendHttpRequest($url, $timeout); Piwik_SetOption(self::LATEST_VERSION, $latestVersion); } catch(Exception $e) { // e.g., disable_functions = fsockopen; allow_url_open = Off + Piwik_SetOption(self::LATEST_VERSION, ''); } - Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1); } } |