An open API service indexing awesome lists of open source software.

https://github.com/neto737/geoip2-update

MaxMind GeoIP update client code
https://github.com/neto737/geoip2-update

Last synced: 5 days ago
JSON representation

MaxMind GeoIP update client code

Awesome Lists containing this project

README

          

# GeoIP2 Update

Update GeoIP2/GeoLite2 databases from your PHP script or automatically via Composer.

## Requirements

- PHP **8.3+**
- `ext-curl`
- `ext-zip` *(only required for CSV database editions)*
- A valid [MaxMind license key](https://support.maxmind.com/account-faq/license-keys/where-do-i-find-my-license-key/)

## Installation

```bash
composer require neto737/geoip2-update
```

## Usage

### 1. Automatic updates via Composer

Add the configuration to your project's `composer.json`. The databases will be checked and updated every time `composer update` or `composer update neto737/geoip2-update` runs.

```json
{
"scripts": {
"post-update-cmd": "neto737\\GeoIP2Update\\ComposerClient::run"
},
"extra": {
"neto737\\GeoIP2Update\\ComposerClient::run": {
"license_key": "YOUR_LICENSE_KEY",
"dir": "@composer/../geoip2"
}
}
}
```

The `@composer` token is replaced with the directory of your `composer.json` file.

### 2. Programmatic updates from PHP

```php
use neto737\GeoIP2Update\Client;

$client = new Client([
'license_key' => 'YOUR_LICENSE_KEY',
'dir' => '/path/to/geoip2',
'editions' => ['GeoLite2-ASN', 'GeoLite2-City', 'GeoLite2-Country'],
]);

$client->run();

foreach ($client->updated() as $message) {
echo $message . PHP_EOL;
}

foreach ($client->errors() as $error) {
echo 'Error: ' . $error . PHP_EOL;
}
```

### 3. Loading the configuration from a GeoIP.conf file

```php
$client = new Client([
'geoipConfFile' => '/etc/GeoIP.conf',
'dir' => '/path/to/geoip2',
]);

$client->run();
```

The `GeoIP.conf` file is the standard MaxMind configuration format:

```
AccountID 12345
LicenseKey YOUR_LICENSE_KEY
EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country
```

## Configuration options

| Option | Type | Description |
|--------|------|-------------|
| `license_key` | `string` | Your MaxMind license key |
| `dir` | `string` | Directory where database files will be stored |
| `editions` | `string[]` | List of edition IDs to update (see below) |
| `geoipConfFile` | `string` | Path to a `GeoIP.conf` file (sets `license_key` and `editions`) |

## Supported editions

| Edition ID | Format |
|------------|--------|
| `GeoLite2-ASN` | MMDB |
| `GeoLite2-City` | MMDB |
| `GeoLite2-Country` | MMDB |
| `GeoIP2-ASN` | MMDB |
| `GeoIP2-City` | MMDB |
| `GeoIP2-Country` | MMDB |
| `GeoLite2-ASN-CSV` | ZIP |
| `GeoLite2-City-CSV` | ZIP |
| `GeoLite2-Country-CSV` | ZIP |
| `GeoIP2-ASN-CSV` | ZIP |
| `GeoIP2-City-CSV` | ZIP |
| `GeoIP2-Country-CSV` | ZIP |

CSV editions require `ext-zip`.

## License

MIT — see [LICENSE](LICENSE).