How to CURL and avoid timeout death (Twitter Down) [migrated]
- by David
Twitter is down right now, and one of my site's home pages relies on getting data from Twitter (relies is the problem - it should be more of an accessory feature, as it just shows follow count from its feed).
Here's the code in question:
function socials_Twitter_GetFollowerCount($username) {
$method = function () use ($username) { return file_get_contents('https://api.twitter.com/1/users/show.json?screen_name='.$username.'&include_entities=true'); };
$json = cache('bmdtwitter', 3600, $method, false);
$json = json_decode($json, true);
return intval($json['followers_count']);
}
What is a good way to make it so if Twitter is down (or not responsive for some reasonable amount of time), our site doesn't appear to be down (I think the timeout maybe defaulting to 30-60 seconds or more).