geocoder-php/ip-info-provider
IP-Info provider for the Geocoder PHP library. Looks up IP addresses using the ipinfo.io service and returns structured location data (country, region, city, coordinates, timezone, etc.) via a simple provider adapter.
ProviderChain, enabling graceful degradation if ipinfo.io fails.city, region, country, lat/lng, timezone) that can be used for:
Laravel → Geocoder → ipinfo.io Provider
ipinfo.io API token (free tier available).| Risk Area | Mitigation Strategy |
|---|---|
| API Rate Limits | Use ipinfo.io’s free tier (1,000 requests/month) or paid plan for scale. Cache responses aggressively (e.g., Redis). |
| Data Accuracy | Validate ipinfo.io’s precision for your use case (e.g., city-level vs. ISP-level accuracy). Fallback to another provider if needed. |
| Vendor Lock-in | Abstract behind a Geocoder interface; swapping providers (e.g., to maxmind/geoip2) requires minimal code changes. |
| Latency | External API calls add ~100–300ms latency. Mitigate with: |
geocoder/adapter/cache)..env (never in code). Use env() helper or Vault for production. |geoip2/geoip2) or return a default location?ipinfo.io’s data usage aligns with GDPR/CCPA (e.g., anonymization for logs).geocoder-php/geocoder)./geocode endpoint in a dedicated service).| Step | Action | Effort | Notes |
|---|---|---|---|
| 1 | Install Geocoder | Low | composer require geocoder-php/geocoder |
| 2 | Add Provider | Low | Register IpInfoProvider in Geocoder’s chain. |
| 3 | Configure API Token | Low | Add to .env: GEOCODER_IPINFO_TOKEN=your_token. |
| 4 | Test Integration | Medium | Verify data fields (city, lat, etc.) match expectations. |
| 5 | Implement Caching | Medium | Add CacheAdapter to reduce API calls. |
| 6 | Add Fallbacks | Optional | Chain with another provider (e.g., GeoIp2Provider). |
| 7 | Monitor Usage | Low | Track API calls vs. rate limits. |
Example Laravel Setup:
// config/geocoder.php
'providers' => [
'ipinfo' => [
'class' => \Geocoder\Provider\IpInfoProvider::class,
'token' => env('GEOCODER_IPINFO_TOKEN'),
'cache' => env('GEOCODER_CACHE', 'array'), // or 'redis'
],
'fallback' => \Geocoder\Provider\GeoIp2\GeoIp2Provider::class,
],
// app/Providers/AppServiceProvider.php
public function register()
{
$geocoder = new \Geocoder\Geocoder();
$geocoder->registerProvider(new \Geocoder\Provider\IpInfoProvider(env('GEOCODER_IPINFO_TOKEN')));
$geocoder->registerProvider(new \Geocoder\Provider\GeoIp2\GeoIp2Provider());
$this->app->singleton('geocoder', fn() => $geocoder);
}
guzzlehttp/guzzle (for HTTP requests).geocoder-php/geocoder (core library).IpInfoProvider for basic geolocation (country/region).ipinfo.io paid plan if needed.geocoder-php/geocoder and ipinfo.io for breaking changes.ipinfo.io rotates keys (unlikely, but check their docs).try {
$geocoder->geocode($ip);
} catch (\Exception $e) {
Log::error("Geocoding failed for IP {$ip}: " . $e->getMessage());
}
GEOCODER.md in your repo with:
ipinfo.io’s accuracy for your IP ranges (e.g., corporate IPs may resolve to HQ).ipinfo.io offers support for paid plans.| Failure Scenario | Impact | Mitigation |
|---|---|---|
ipinfo.io API |
How can I help you explore Laravel packages today?