Custom GeoIP Function: Operation Timed Out

  • Ads

Custom GeoIP Function: Operation Timed Out

Postby GRS88 » Sat May 01, 2010 12:17 pm

Hey,

I wrote a function in PHP which queries the API. I just checked my error log, and I've noticed that I've been seeing a lot of errors.
PHP Warning: file_get_contents(http://ipinfodb.com/ip_query.php?ip=x.x.x.x&timezone=false): failed to open stream: Operation timed out in /usr/local/www/main/includes/functions.inc.php on line 1454

I've been steadily increasing the "timeout" value of the file_get_contents() call, but it doesn't seem to help at all. It went from 5 seconds to 30 seconds, and I still see the error messages. Is this a problem on my end, or is the server(s) having issues? It would not be a network connection on my end, as I run several other services (such as IRC) which have been acting fine, so if it is on my end, it would be a coding error.

Note, I don't see any error entries for "http://backup.ipinfodb.com", only "http://ipinfodb.com"

Here's my function: http://pastie.org/private/rohx6d1a5m3p6eyiitldq
(I prefer not to use ini_set('default_socket_timeout') because I have other socket functions, so I don't want to disturb them)

Thanks!
GRS88
 
Posts: 2
Joined: Wed Apr 07, 2010 10:48 am

Re: Custom GeoIP Function: Operation Timed Out

Postby marchost » Mon May 03, 2010 9:42 pm

Hi, the only thing I see is that you go over the 2 queries per second limit... I monitor the APIs every minute and I get less than 1 warning per 1-2 month so I would be surprised that there was a network or server overload problem. Your code looks fine but did you try the PHP class available on the API page?
marchost
Site Admin
 
Posts: 373
Joined: Wed Apr 08, 2009 9:55 pm

Re: Custom GeoIP Function: Operation Timed Out

Postby jts » Tue May 04, 2010 5:22 pm

GRS88:

You may want to consider using the cURL library to make your outgoing API calls. file_get_contents() is a good "quick n' dirty" way to call external web services, but I have the impression that it was made for local file retrieval and just as a "courtesy" can call external URLs. cURL gives one much more granular control in making such external calls, is made specifically for it, and is easy to use.

Here's a helpful wrapper function to make cURL calls even easier to make - cURLfriend(). It will probably work for you right out of the box (you can even specify a timeout right within the function call), or maybe with some minor tweaking.

http://www.helios825.org/cURLfriend.php

Good luck.

-jts
jts
 
Posts: 2
Joined: Tue May 04, 2010 4:59 pm


Return to IP geolocation API related



Who is online

Users browsing this forum: No registered users and 1 guest

cron