Torann / laravel-geoip

Determine the geographical location of website visitors based on their IP addresses.
http://lyften.com/projects/laravel-geoip
BSD 2-Clause "Simplified" License
2.09k stars 372 forks source link

geoip.ERROR: Exception: Request failed (Connection timed out after 20000 milliseconds) in /vendor/torann/geoip/src/Services/IPApi.php:66 #103

Closed niqitos closed 5 years ago

niqitos commented 6 years ago

Hello,

I ran into this error on one of my sites hosted in the UK. As a result, the site is using default_location from config. Everything worked perfectly from Feb 13 until Feb 26 when I got this error in geoip.log.

I have another site hosted in the US, and everything works fine there.

Indeed, in Tinker \GeoIP::getLocation()->country works fast and returns the correct location on the US hosted site, but works very slow and returns default location on the UK hosted site and logs the following error:

geoip.ERROR: Exception: Request failed (Connection timed out after 20000 milliseconds) in /vendor/torann/geoip/src/Services/IPApi.php:66 Stack trace:

0 /vendor/torann/geoip/src/GeoIP.php(148): Torann\GeoIP\Services\IPApi->locate('199.16.157.180')

1 /vendor/torann/geoip/src/GeoIP.php(114): Torann\GeoIP\GeoIP->find('199.16.157.180')

2 /bootstrap/cache/compiled.php(6323): Torann\GeoIP\GeoIP->getLocation()

3 /app/Http/Middleware/LocationCurrency.php(23): Illuminate\Support\Facades\Facade::__callStatic('getLocation', Array)

4 [internal function]: App\Http\Middleware\LocationCurrency->handle(Object(Illuminate\Http\Request), Object(Closure))

5 bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

6 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

7 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

8 /bootstrap/cache/compiled.php(3225): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

9 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))

10 /bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

11 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

12 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

13 /bootstrap/cache/compiled.php(13474): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

14 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))

15 /bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

16 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

17 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

18 /bootstrap/cache/compiled.php(11964): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

19 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))

20 /bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

21 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

22 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

23 /bootstrap/cache/compiled.php(13213): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

24 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))

25 /bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

26 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

27 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

28 /bootstrap/cache/compiled.php(13150): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

29 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))

30 /bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

31 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

32 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

33 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

34 /bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

35 /bootstrap/cache/compiled.php(8226): Illuminate\Pipeline\Pipeline->then(Object(Closure))

36 /bootstrap/cache/compiled.php(8217): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))

37 /bootstrap/cache/compiled.php(8207): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

38 /bootstrap/cache/compiled.php(2419): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

39 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}(Object(Illuminate\Http\Request))

40 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

41 /bootstrap/cache/compiled.php(3286): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

42 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))

43 /bootstrap/cache/compiled.php(9963): call_user_func_array(Array, Array)

44 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

45 /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

46 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

47 /bootstrap/cache/compiled.php(9948): call_user_func(Object(Closure), Object(Illuminate\Http\Request))

48 /bootstrap/cache/compiled.php(2366): Illuminate\Pipeline\Pipeline->then(Object(Closure))

49 /bootstrap/cache/compiled.php(2350): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))

50 /public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))

51 {main} [] []

I don't know what is causing this behaviour but thought maybe the location of the servers may have something to do with it. Everything is configured pretty basically. I use the service only once in middleware for currency detection and then cache it.

$geoCurrency = GeoIP::getLocation()->currency; Cookie::queue('currency', $geoCurrency, 525600);

Thank you in advance! Best regards, Nik

matiasditata-di commented 5 years ago

Hi Nick,

I've bumped with the same issue recently. If you are using ip-api, try to unban your IP here . It did the trick for me.

I hope that helps. Best, Mat.-

ashu555 commented 5 years ago

Yeah so everytime the ip gets banned do we need to unban the ip? Isn't there a permanent fix for this. According to ip-api documentation if there are more than 150 requests per minute the ip will get banned.

bvweijen commented 3 years ago

@Torann Why is this one closed? Is there a solution? I'm experiencing the same problems

Torann commented 3 years ago

This is an issue with ip-api or your sever. I wouldn't recommend depending on a third-party service in a way that if it fails it causes your application to fail. I would recommend using the Maxmind local DB