Geo lookup timeout possible?

59 views
Skip to first unread message

Chris Maxwell

unread,
Feb 19, 2018, 9:44:00 AM2/19/18
to Fat-Free Framework
A couple of days ago we had a page that would not load - the loading wheel was just spinning constantly.

After troubleshooting we tracked this down to the line in our code which gets the user's geo-location:

$loc = $geo->location(); // locate specific IP

My guess is the server was unable to connect to the Maxmind service to get the location information due to some unknown reason. When I retried the page at a later time it was working fine, so the problem was only temporary.

Is there any way we can configure a timeout on this so that it times out gracefully instead of waiting indefinitely and preventing the page from loading?

Thanks,
Chris

ved

unread,
Feb 19, 2018, 10:29:35 AM2/19/18
to Fat-Free Framework
Hi,

As you can see from the source file, that method doesn't really connect to Maxmind.
What it does is check if you have Maxmind's database locally installed (using geoip_db_avail) and, if that fails, then it tries to contact an online service (geoplugin.net). It was probably this online fallback that probably timed out.

To avoid this, please confirm that you have maxmind installed on your server. If using Debian or Ubuntu, I recommend installing the package named "geoip-database-contrib" which downloads the geoip database and setups periodic jobs to update them.

Cheers.

Chris Maxwell

unread,
Feb 19, 2018, 11:56:21 AM2/19/18
to Fat-Free Framework
Thanks for your reply and for the information.

I checked if the Maxmind database was available using the geoip_db_avail() function, and it wasn't. So I installed it on the server and now geo lookups will hopefully use the Maxmind local database instead of the remote service.

Thanks again!

Chris Maxwell

unread,
Feb 28, 2018, 12:22:10 PM2/28/18
to Fat-Free Framework
For IP's in the US we are seeing the following error occurring (resulting in a 500 server error):

Internal Server Error

geoip_region_name_by_code
(): You need to specify the country and region codes.[lib/base.php:2178] Base->error()
[lib/web/geo.php:68] geoip_region_name_by_code()
[app/pages.php:19] Web\Geo->location()
[lib/base.php:1612] Base->call()
[index.php:16] Base->run()

This happens for testing with USA IP's such as 8.8.8.8, but for European (and other) addresses it works fine.

The code to produce this is as follows:

$geo = \Web\Geo::instance();
$loc
= $geo->location('8.8.8.8'); // locate specific IP

To confirm that we have the
GeoIP Database I checked the version with geoip_db_avail(GEOIP_COUNTRY_EDITION) and it's as follows:

GEO-106FREE 20180102 Build 1 Copyright (c) 2018 MaxMind Inc All Rights Reserved

Do you have any ideas how we can prevent the error from occurring for US addresses?

Thanks in advance.

ikkez

unread,
Mar 5, 2018, 9:09:21 AM3/5/18
to Fat-Free Framework
It's probably failing because the region code cannot be found and that function doesn't seem to like empty strings for its parameters. So it should be fixed in the latest commit now ;)

Chris Maxwell

unread,
Mar 6, 2018, 1:57:17 PM3/6/18
to Fat-Free Framework
That's great, thanks for fixing this.

Out of interest, when will the latest commit be added to the stable release of the framework? Currently we are running F3 v3.6 as downloaded from the website (master.zip) and I would prefer to continue to use tried and tested code where possible.
Reply all
Reply to author
Forward
0 new messages