2017 © Pedro Peláez
 

library reader

MaxMind DB Reader API

image

maxmind-db/reader

MaxMind DB Reader API

  • Wednesday, May 23, 2018
  • by oschwald
  • Repository
  • 36 Watchers
  • 217 Stars
  • 7,681,768 Installations
  • PHP
  • 23 Dependents
  • 0 Suggesters
  • 42 Forks
  • 10 Open issues
  • 20 Versions
  • 8 % Grown

The README.md

MaxMind DB Reader PHP API

Description

This is the PHP API for reading MaxMind DB files. MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6)., (*1)

Installation (Composer)

We recommend installing this package with Composer., (*2)

Download Composer

To download Composer, run in the root directory of your project:, (*3)

curl -sS https://getcomposer.org/installer | php

You should now have the file composer.phar in your project directory., (*4)

Install Dependencies

Run in your project root:, (*5)

php composer.phar require maxmind-db/reader:~1.0

You should now have the files composer.json and composer.lock as well as the directory vendor in your project directory. If you use a version control system, composer.json should be added to it., (*6)

Require Autoloader

After installing the dependencies, you need to require the Composer autoloader from your code:, (*7)

require 'vendor/autoload.php';

Installation (Standalone)

If you don't want to use Composer for some reason, a custom autoload.php is provided for you in the project root. To use the library, simply include that file,, (*8)

require('/path/to/MaxMind-DB-Reader-php/autoload.php');

and then instantiate the reader class normally:, (*9)

use MaxMind\Db\Reader;
$reader = new Reader('example.mmdb');

Installation (RPM)

RPMs are available in the official Fedora repository., (*10)

To install on Fedora, run:, (*11)

dnf install php-maxminddb

To install on CentOS or RHEL 7, first enable the EPEL repository and then run:, (*12)

yum install php-maxminddb

Please note that these packages are not maintained by MaxMind., (*13)

Usage

Example

<?php
require_once 'vendor/autoload.php';

use MaxMind\Db\Reader;

$ipAddress = '24.24.24.24';
$databaseFile = 'GeoIP2-City.mmdb';

$reader = new Reader($databaseFile);

// get returns just the record for the IP address
print_r($reader->get($ipAddress));

// getWithPrefixLen returns an array containing the record and the
// associated prefix length for that record.
print_r($reader->getWithPrefixLen($ipAddress));

$reader->close();

Optional PHP C Extension

MaxMind provides an optional C extension that is a drop-in replacement for MaxMind\Db\Reader. In order to use this extension, you must install the Reader API as described above and install the extension as described below. If you are using an autoloader, no changes to your code should be necessary., (*14)

Installing Extension

First install libmaxminddb as described in its README.md file. After successfully installing libmaxmindb, you may install the extension from pecl:, (*15)

pecl install maxminddb

Alternatively, you may install it from the source. To do so, run the following commands from the top-level directory of this distribution:, (*16)

cd ext
phpize
./configure
make
make test
sudo make install

You then must load your extension. The recommended method is to add the following to your php.ini file:, (*17)

extension=maxminddb.so

Note: You may need to install the PHP development package on your OS such as php5-dev for Debian-based systems or php-devel for RedHat/Fedora-based ones., (*18)

128-bit Integer Support

The MaxMind DB format includes 128-bit unsigned integer as a type. Although no MaxMind-distributed database currently makes use of this type, both the pure PHP reader and the C extension support this type. The pure PHP reader requires gmp or bcmath to read databases with 128-bit unsigned integers., (*19)

The integer is currently returned as a hexadecimal string (prefixed with "0x") by the C extension and a decimal string (no prefix) by the pure PHP reader. Any change to make the reader implementations always return either a hexadecimal or decimal representation of the integer will NOT be considered a breaking change., (*20)

Support

Please report all issues with this code using the GitHub issue tracker., (*21)

If you are having an issue with a MaxMind service that is not specific to the client API, please see our support page., (*22)

Requirements

This library requires PHP 7.2 or greater., (*23)

The GMP or BCMath extension may be required to read some databases using the pure PHP API., (*24)

Contributing

Patches and pull requests are encouraged. All code should follow the PSR-1 and PSR-2 style guidelines. Please include unit tests whenever possible., (*25)

Versioning

The MaxMind DB Reader PHP API uses Semantic Versioning., (*26)

This software is Copyright (c) 2014-2024 by MaxMind, Inc., (*27)

This is free software, licensed under the Apache License, Version 2.0., (*28)

The Versions

23/05 2018

dev-master

9999999-dev https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

database geoip geolocation maxmind geoip2

22/05 2018

dev-dlieou/HHVM-wording

dev-dlieou/HHVM-wording https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

database geoip geolocation maxmind geoip2

21/02 2018

v1.3.0

1.3.0.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

database geoip geolocation maxmind geoip2

21/02 2018

dev-greg/ext-open-basedir

dev-greg/ext-open-basedir https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

database geoip geolocation maxmind geoip2

27/10 2017

v1.2.0

1.2.0.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

database geoip geolocation maxmind geoip2

20/01 2017

v1.1.3

1.1.3.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

21/11 2016

v1.1.2

1.1.2.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

15/09 2016

v1.1.1

1.1.1.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

04/01 2016

v1.1.0

1.1.0.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

13/03 2015

v1.0.3

1.0.3.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

19/01 2015

v1.0.2

1.0.2.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

13/01 2015

v1.0.1

1.0.1.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

22/09 2014

v1.0.0

1.0.0.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

17/09 2014

dev-greg/coverity

dev-greg/coverity https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

15/09 2014

v0.3.3

0.3.3.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

10/09 2014

v0.3.2

0.3.2.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

01/05 2014

v0.3.1

0.3.1.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind geoip2

19/02 2014

v0.3.0

0.3.0.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

Apache-2.0

The Requires

  • ext-bcmath *
  • php >=5.3.1

 

The Development Requires

database geoip geolocation maxmind

21/10 2013

v0.2.0

0.2.0.0 https://github.com/maxmind/MaxMind-DB-Reader-php

MaxMind DB Reader API

  Sources   Download

LGPL-2.1+

The Development Requires

database geoip geolocation maxmind

16/07 2013

v0.1.0

0.1.0.0 https://github.com/maxmind/MaxMind-DB-php

MaxMind DB Reader API

  Sources   Download

LGPL-2.1+

The Development Requires

database geoip geolocation maxmind