Giter VIP home page Giter VIP logo

geoip2-update's Introduction

geoip2-update-logo

Geoip2 Update is a php tool for updating Maxmind GeoLite2 and GeoIP2 databases from your script, application or via Composer.

Latest Stable Version GitHub downloads

REQUIREMENTS

The minimum requirement of this library is for your web server to support PHP >= 5.3.0 with curl extension and an optional zip extension if you want to update the csv databases.

INSTALLATION

If you do not have Composer, you may install it by following the instructions at getcomposer.org.

You can then install this library using the following command:

composer require tronovav/geoip2-update

CONFIGURATION

1. Updating databases via Composer.

To update Geoip2 databases via Composer, you can set up an update call in your composer.json. Each time the composer update command is invoked, the library will check for updates on the "maxmind.com" server and update the Geoip2 databases if necessary. You can also update only GeoIP2 databases without updating all project dependencies: composer update tronovav/geoip2-update.

1.1. Use in-line configuration options:

# composer.json

"scripts": {
        "post-update-cmd": [
            "tronovav\\GeoIP2Update\\ComposerClient::run"
        ]
},
"extra": {
    "tronovav\\GeoIP2Update\\ComposerClient::run": {
        "license_key": "MAXMIND_LICENSE_KEY",
        "dir": "DESTINATION_DIRECTORY_PATH",
        "editions": ["GeoLite2-ASN", "GeoLite2-City", "GeoLite2-Country"]
    }
}

Parameters in the scripts section:

Just add the "post-update-cmd": "tronovav\\GeoIP2Update\\ComposerClient::run" line to update databases via Composer.

Parameters in the extra section:

  • license_key (required) - You can see your license key information on your account License Keys page at maxmind.com.
  • dir (required) - Absolute path to the Geoip2 local database storage directory. Or you can alias part of the path relative to your composer.json. For example @composer/path-to-db-storage. The script itself will find the absolute path to the composer.json file in your project and the path-to-db-storage directory for storing Geoip2 databases relative to composer.json. You can also specify @composer/../path-to-db-storage. The main thing is that you yourself understand which path to storing the database you specify.
  • editions - List of database editions that you want to update. Maxmind.com offers databases for free download: GeoLite2-ASN, GeoLite2-City, GeoLite2-Country, GeoLite2-ASN-CSV, GeoLite2-City-CSV, GeoLite2-Country-CSV. If you do not specify the editions parameter, then the databases will be updated: GeoLite2-ASN, GeoLite2-City, GeoLite2-Country. Otherwise, only the editions that you specified will be updated. See available editions in your maxmind.com account.

1.2. Use GeoIP.conf file:

Instead of the parameters license_key and editions, you can specify the path to the configuration file. The configuration file format fully complies with the recommendations of maxmind.com on the documentation page: Obtain GeoIP.conf with Account Information

# composer.json

"scripts": {
        "post-update-cmd": [
            "tronovav\\GeoIP2Update\\ComposerClient::run"
        ]
},
"extra": {
    "tronovav\\GeoIP2Update\\ComposerClient::run": {
        "dir": "DESTINATION_DIRECTORY_PATH",
        "geoipConfFile": "DESTINATION_GEOIP_CONFIG_FILE"
    }
}

Parameters in the extra section:

  • dir (required) - Absolute path to the Geoip2 local database storage directory. Or you can alias part of the path relative to your composer.json. For example @composer/path-to-db-storage. The script itself will find the absolute path to the composer.json file in your project and the path-to-db-storage directory for storing Geoip2 databases relative to composer.json. You can also specify @composer/../path-to-db-storage or another path relative to your file composer.json.
  • geoipConfFile (required) - The absolute path to the configuration file. Or you can alias part of the path relative to your composer.json. For example @composer/../GeoIP.conf.

2. Updating databases from your php application.

You can use this option to update GeoIP2 databases from your project, or use Cron on Linux, or use Task Scheduler on Windows.

2.1. Use in-line configuration options:

<?php

require 'vendor/autoload.php';

// configuration
$client = new \tronovav\GeoIP2Update\Client(array(
    'license_key' => 'MAXMIND_LICENSE_KEY',
    'dir' => 'DESTINATION_DIRECTORY_PATH',
    'editions' => array('GeoLite2-ASN', 'GeoLite2-City', 'GeoLite2-Country'),
));
// run update
$client->run();

Params:

  • license_key (required) - You can see your license key information on your account License Keys page at maxmind.com.
  • dir (required) - Absolute path to the local storage of Geoip2 databases.
  • editions - List of database editions that you want to update. Maxmind.com offers databases for free download: GeoLite2-ASN, GeoLite2-City, GeoLite2-Country, GeoLite2-ASN-CSV, GeoLite2-City-CSV, GeoLite2-Country-CSV. If you do not specify the editions parameter, then the databases will be updated: GeoLite2-ASN, GeoLite2-City, GeoLite2-Country. Otherwise, only the editions that you specified will be updated. See available editions in your maxmind.com account.

2.2. Use GeoIP.conf file:

Instead of the parameters license_key and editions, you can specify the path to the configuration file. The configuration file format fully complies with the recommendations of maxmind.com on the documentation page: Obtain GeoIP.conf with Account Information

<?php

require 'vendor/autoload.php';

// configuration
$client = new \tronovav\GeoIP2Update\Client(array(
    'dir' => 'DESTINATION_DIRECTORY_PATH',
    "geoipConfFile" => "DESTINATION_GEOIP_CONFIG_FILE",
));
// run update
$client->run();

Params:

  • dir (required) - Absolute path to the local storage of Geoip2 databases.
  • geoipConfFile (required) - The absolute path to the configuration file.

After the update, you can get information about the result, if you need it:

print_r($client->updated()); // update result

print_r($client->errors()); // update errors

DATABASES AVAILABLE FOR UPDATING

Available Edition ID databases that you can specify in the editions parameter or in the configuration file to update them.

  • GeoLite2-ASN

  • GeoLite2-City

  • GeoLite2-Country

  • GeoLite2-ASN-CSV

  • GeoLite2-City-CSV

  • GeoLite2-Country-CSV

  • GeoIP2-ASN

  • GeoIP2-City

  • GeoIP2-Country

  • GeoIP2-ASN-CSV

  • GeoIP2-City-CSV

  • GeoIP2-Country-CSV

See available Edition ID databases for updates in your maxmind.com account.

DATABASE UPDATE ATOMICITY

The atomicity of the update operation is implemented at the level of the database files.

The structure of the mmdb and csv databases is different. Mmdb databases consist of a single database file. Thus, when updating the mmdb databases, the operation is completely atomic and errors associated with the short-term absence of the mmdb file during the database update are excluded. Since the files are atomically replaced with new ones.

CSV databases consist of multiple files. When upgrading versions of the CSV database, each CSV file is also replaced atomically, and there is no chance of a file missing during the upgrade.

COPYRIGHT AND LICENSE

This software is Copyright (c) 2021 by Andrey Tronov.

This is free software, licensed under the MIT License.

geoip2-update's People

Contributors

oschwald avatar tronovav avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.