I have a site that uses file_get_contents to access a geolocation API on every request. From time to time this remote API starts giving 504/502 errors, presumably due to problems at their end. The problem is that this causes my site to go down also - is there a way to create a fallback so that if the remote site starts timing out it will ignore it and load the page anyway?
This is my code:
$geoData = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']));