geocoder-php/maxmind-provider
MaxMind provider for PHP-Geocoder. Integrates MaxMind GeoIP databases to resolve IP addresses into location data (country, region, city, coordinates). Useful for adding fast, offline IP geolocation to your PHP apps.
geocoder-php ecosystem. It fits well in systems requiring IP-to-geolocation resolution (e.g., analytics, fraud detection, localization).Request object and service container can easily integrate this provider via dependency injection, reducing boilerplate for geocoding logic..mmdb files), enabling offline use or cloud-hosted databases (e.g., AWS S3, MaxMind’s API).cache() facade can wrap provider calls to mitigate rate limits or reduce MaxMind API costs.geocoder-php/freegeoip-provider)..mmdb files require memory-mapped I/O, which may impact Laravel’s worker processes (e.g., queues). Test with:
maxmindio/maxmind-php for direct .mmdb access)..mmdb files be updated/versioned (e.g., automated CI/CD pipeline)?MaxMindProvider as a bindable service in AppServiceProvider:
$this->app->bind(\Geocoder\Provider\MaxMind\MaxMind::class, function ($app) {
return new \Geocoder\Provider\MaxMind\MaxMind($app['config']['services.maxmind.database_path']);
});
Geocoder::geocode($ip)) to abstract provider logic.GeocodeRequestMiddleware):
public function handle($request, Closure $next) {
$request->merge(['geo' => app(MaxMind::class)->geocode($request->ip())]);
return $next($request);
}
geocoder-php/mock-provider) in PHPUnit.UserController) with the MaxMind provider.geocoder-php/google-maps-provider)..mmdb files in Laravel’s storage/app/ or a CDN (e.g., Cloudflare R2).// app/Console/Commands/UpdateMaxMindDB.php
public function handle() {
$this->updateDatabaseFromMaxMindAPI();
}
geocoder-php (v4+).maxmindio/maxmind-php (v1.0+) for .mmdb parsing.guzzlehttp/guzzle (Laravel’s default HTTP client)..mmdb file from MaxMind.storage/app/maxmind/GeoLite2-City.mmdb.config/services.php:
'maxmind' => [
'database_path' => storage_path('app/maxmind/GeoLite2-City.mmdb'),
'account_id' => env('MAXMIND_ACCOUNT_ID'), // For cloud API
],
/api/analytics).MaxMindProviderException).geocoder-php/geocoder and maxmindio/maxmind-php for breaking changes.\Log::debug('Geocoding result', ['data' => $result->getCoordinates()]);
.mmdb files can be large (MBs to GBs). Use memory limits in php.ini:
memory_limit = 512M
geocode:delayed job).GeoLite2 for non-critical paths.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| MaxMind API downtime | Geocoding fails for cloud users. | Fallback to local .mmdb or free tier. |
Corrupted .mmdb file |
All geocoding requests fail. | Checksum validation on update. |
| PHP memory exhaustion | Worker crashes on large files. | Increase memory_limit or use streaming. |
| Rate limiting (cloud API) | Throttled requests. | Implement exponential backoff. |
| IP not found in database | Inaccurate or missing data. | Log and alert on high error rates. |
docs/geocoding.md.README.md.How can I help you explore Laravel packages today?