Skip to content

Commit

Permalink
Empty commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Git committed Jun 11, 2014
1 parent 8bcb79a commit 04e21fe
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion classes/lastfm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ private static function lastfm_request($Method, $Args) {
if (!defined('LASTFM_API_KEY')) {
return false;
}
$RecentFailsKey = 'lastfm_api_fails';
$RecentFails = (int)G::$Cache->get_value($RecentFailsKey);
if ($RecentFails > 5) {
// Take a break if last.fm's API is down/nonfunctional
return false;
}
$Url = LASTFM_API_URL . $Method;
if (is_array($Args)) {
foreach ($Args as $Key => $Value) {
Expand All @@ -180,11 +186,16 @@ private static function lastfm_request($Method, $Args) {

$Curl = curl_init();
curl_setopt($Curl, CURLOPT_HEADER, 0);
curl_setopt($Curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($Curl, CURLOPT_TIMEOUT, 3);
curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($Curl, CURLOPT_URL, $Url);
$Return = curl_exec($Curl);
$Errno = curl_errno($Curl);
curl_close($Curl);
if ($Errno) {
G::$Cache->cache_value($RecentFailsKey, $RecentFails + 1, 1800);
return false;
}
return json_decode($Return, true);
}
}
Expand Down

0 comments on commit 04e21fe

Please sign in to comment.