Today the ipinfodb server went down, creating disruption in all these applications that use the service for identifying a user’s location via their IP address.

The script provided by ipinfodb, does not have a timeout option, resulting in the function hanging for 30 seconds or more (depending on your PHP time out settings.)

The solution:

Add a context to the file_get_content function on the Geolocation class:

$context = stream_context_create(array(
'http' => array(
'timeout' => 3 // Timeout in seconds

… and then call file_get_contents with that context:
$xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . 'ip_query_country.php?key=' . $this->apiKey . '&ip=' . $ip, 0, $context);

This will force a timeout of 3 seconds if IPinfodb servers are down.

One thought on “IPInfodb server down? Solution for timeout

  1. Hey I am so glad I found your webpage, I really found you by mistake, while I was looking on Digg for something else,
    Anyhow I am here now and would just like to say thanks
    for a incredible post and a all round enjoyable blog (I also love the theme/design), I donít have time to look over it
    all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I
    will be back to read much more, Please do keep up the
    superb b.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>