PHP Reader for the MaxMind DB Database Format

Overview

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).

Installation (Composer)

We recommend installing this package with Composer.

Download Composer

To download Composer, run in the root directory of your project:

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

You should now have the file composer.phar in your project directory.

Install Dependencies

Run in your project root:

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.

Require Autoloader

After installing the dependencies, you need to require the Composer autoloader from your code:

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,

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

and then instantiate the reader class normally:

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

Installation (RPM)

RPMs are available in the official Fedora repository.

To install on Fedora, run:

dnf install php-maxminddb

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

yum install php-maxminddb

Please note that these packages are not maintained by MaxMind.

Usage

Example


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.

Installing Extension

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

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:

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:

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.

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.

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.

Support

Please report all issues with this code using the GitHub issue tracker.

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

Requirements

This library requires PHP 7.2 or greater.

The GMP or BCMath extension may be required to read some databases using the pure PHP API.

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.

Versioning

The MaxMind DB Reader PHP API uses Semantic Versioning.

Copyright and License

This software is Copyright (c) 2014-2021 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0.

Comments
  • SIGSEGV with native C extension when IP queried is null/empty string

    SIGSEGV with native C extension when IP queried is null/empty string

    As simple as that.

    [14-Dec-2019 09:27:16] WARNING: [pool www] child 2662 exited on signal 11 (SIGSEGV) after 133.373968 seconds from start
    

    Example code:

    $res = $this->reader->country($ip)->country->isoCode;
    
    opened by proton-ab 17
  • Exception:

    Exception: "Something bad happened"

    Hi all,

    I'm trying to track down this error, which occurs in the findAddressInTree method in Reader. The error occurs in my Slim 4 application, which accesses the reader via middleware (in the process method):

    ...
    $reader = new Reader($this->dbFilename);
    $record = $reader->get($ip);
    $request = $request->withAttribute('country_code', $record['country']['iso_code']);
    ...
    

    I don't get the error when I manually access the database from a simple command line script:

    <?php
    
    require '/path/to/vendor/autoload.php';
    
    $reader = new \MaxMind\Db\Reader('/path/to/GeoIP2-Country.mmdb');
    var_dump($reader->get("IP_GOES_HERE")['country']['iso_code']);
    

    This is in PHP 7.4 (using PHP-FPM and Apache 2.4.29), and I'm using version 1.8.0 of the MaxMind DB reader, with the extension compiled and enabled. Note that I had this same error prior to using the extension, and also with the geoip2 package.

    What does this error mean, and do you have any suggestions on how I can proceed with debugging it?

    opened by milesizzo 8
  • Metadata's buildEpoch parsed as a string instead of integer.

    Metadata's buildEpoch parsed as a string instead of integer.

    Hello.

    I'm using this library in a project where I have a small mechanism to programatically update the GeoLite2 database file from time to time.

    The logic is based on the database file build epoch, which I'm getting from the MaxMind\Db\Reader\Metadata object.

    This object states that the buildEpoch property is an integer:

    image

    However, I have a user that has reported an error because that value is coming as a string, and is making a later statement fail because there's a type hint to int somewhere else.

    I haven't been able to reproduce it myself, but I have asked him to var_dump the metadata object, and it has been parsed as a string for him.

    object(MaxMind\Db\Reader\Metadata)#161 (11) {
      ["binaryFormatMajorVersion"]=>
      int(2)
      ["binaryFormatMinorVersion"]=>
      int(0)
      ["buildEpoch"]=>
      string(10) "1611667589"
      ["databaseType"]=>
      string(13) "GeoLite2-City"
      ["description"]=>
      array(1) {
        ["en"]=>
        string(22) "GeoLite2 City database"
      }
      ["ipVersion"]=>
      int(6)
      ["languages"]=>
      array(8) {
        [0]=>
        string(2) "de"
        [1]=>
        string(2) "en"
        [2]=>
        string(2) "es"
        [3]=>
        string(2) "fr"
        [4]=>
        string(2) "ja"
        [5]=>
        string(5) "pt-BR"
        [6]=>
        string(2) "ru"
        [7]=>
        string(5) "zh-CN"
      }
      ["nodeByteSize"]=>
      int(7)
      ["nodeCount"]=>
      int(4150659)
      ["recordSize"]=>
      int(28)
      ["searchTreeSize"]=>
      int(29054613)
    }
    

    I asked him to share his database file, and for me it's parsed as an integer, so I'm not sure what could be the difference.

    Is there a known combination of circumstances in which this could end up happening?

    I have considered just casting the value to integer always, but I'm afraid that could mask other errors that would be harder to identify later on.

    opened by acelaya 7
  • Add config.w32 for building on Windows

    Add config.w32 for building on Windows

    This is a minimal config.w32 for building php_maxminddb.dll on Windows. Tests with a GeoIP2-City.mmdb in \usr\local\share\GeoIP

    =====================================================================
    Number of tests :    3                 3
    Tests skipped   :    0 (  0.0%) --------
    Tests warned    :    0 (  0.0%) (  0.0%)
    Tests failed    :    0 (  0.0%) (  0.0%)
    Expected fail   :    0 (  0.0%) (  0.0%)
    Tests passed    :    3 (100.0%) (100.0%)
    ---------------------------------------------------------------------
    Time taken      :    0 seconds
    =====================================================================
    

    It works for PHP 7.0 - 7.4 and PHP 8.0, provided the libmaxminddb dependencies are in deps/lib and deps/include. Please review and merge.

    See a phpinfo dump: https://phpdev.toolsforresearch.com/php-8.0.1RC1-nts-Win32-vs16-x64.htm

    And the complete distro https://phpdev.toolsforresearch.com/php-8.0.1RC1-nts-Win32-vs16-x64.zip

    opened by Jan-E 7
  • error when install c extension for php7

    error when install c extension for php7

    after compiling and install of maxminddb . I start to config and install to get the maxminddb.so . but when i restart the php7 service . i get this error: NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/opt/remi/php70/root/usr/lib64/php/modules/maxminddb.so' - /opt/remi/php70/root/usr/lib64/php/modules/maxminddb.so: undefined symbol: zval_used_for_init in Unknown on line 0

    opened by leolikescoding 7
  • Improve performance of Reader.php

    Improve performance of Reader.php

    Buffering the database file in memory significantly improves the reader performance. Specially noticeable with very large amount of IP to search location for.

    enhancement 
    opened by FrancoisChaumont 6
  • Remove development stuff from releases

    Remove development stuff from releases

    composer require currently downloads all the contents of the repository, but for production usage the development stuff is not required (and it could may be harmful if it contains executable files).

    What about removing this development stuff from releases?

    This affects only installing releases: git-cloning is not touched, so that people that want to run tests/build phars can perform a git clone

    opened by mlocati 6
  • Cache I/O when doing several IP searches in the same instance

    Cache I/O when doing several IP searches in the same instance

    I store the mmdb database in a remote filesystem, which has slow random I/O. When profiling with xhprof I found that the hotspot for my use case was the native fread() and fseek() calls (90%+ of the time), so I made a little hack to optimize it a bit and avoid a few duplicated reads when doing several seeks in the same run (i.e. instantiate once, seek multiple times).

    For that use case (500 random IP queries) I measured the following maximum queries per second after several runs:

    • base: 10 QPS (~500 KB used)
    • ftell: 25 QPS (~500 KB used)
    • inner cache: 40 QPS (~2600 KB used)
    • inner cache + ftell: 85 QPS (~2600 KB used) (Measured with PHP 5.3.3-7+squeeze17 with Suhosin in Debian 6)

    The higher memory usage might be a problem for some setups, so I understand that it wouldn't be suitable for the project goals, but in my case it was a nice trade and it may be useful to someone else.

    opened by martinml 6
  • Add package.xml for PECL package

    Add package.xml for PECL package

    @remicollet, would you be willing to review this when you get a chance? I wrote this by hand. I am not sure if there is an specific tooling you would recommend.

    Also, I noticed that running pear package rewrites the file. Would you recommend committing those changes? From looking at other people's repos, it appears some people do commit the pear version and others don't.

    Thank you!

    opened by oschwald 5
  • With PHP C extension getting considerably worse peformance

    With PHP C extension getting considerably worse peformance

    I installed the PHP C extension in an environment where every millisecond matters and it loads and it works, but we are getting far worse performance with the extension enabled compared to just using straight PHP.

    With the C extension it can take anywhere from 1.5 s to 0.005. Most of the time it is over 0.8s. With the C extensions disabled using just the PHP classes the performance is constant around 0.15s.

    Running a script from command line with a fixed IP address with the classes installed from Composer.

    Here is my test code:

    <?php
    $t = microtime(true);
    require 'vendor/autoload.php';
    $reader = new \GeoIp2\Database\Reader(__DIR__ . '/GeoLite2-City.mmdb');
    $ip = '8.8.8.8'; // Actually using my own IP, but don't want to include that here.
    $record = $reader->city($ip);
    echo microtime(true) - $t;
    ?>
    

    Is there anything I could have done wrong? Any help you can provide?

    opened by marcusds 5
  • Segmentation fault in ext/maxminddb.c:418

    Segmentation fault in ext/maxminddb.c:418

    Hi,

    My developers get a segmentation fault when trying to integrate the maxminddb module into their testing suite. Apparently some simple accesses work, but when doing some less usual stuff (extending a class and overriding its constructor, I think) it breaks. This is with the 1.0.0 code (you can see the exact hash in the debuginfo file path) and PHP 5.5.19 with GeoIP2-Country.mmdb.

    Let me know if you need more information.

    Core was generated by `php bin/phpspec run'.
    Program terminated with signal 11, Segmentation fault.
    #0  zend_hash_destroy (ht=0x0) at /usr/src/debug/php-5.5.19/Zend/zend_hash.c:555
    555     p = ht->pListHead;
    #0  zend_hash_destroy (ht=0x0) at /usr/src/debug/php-5.5.19/Zend/zend_hash.c:555
    #1  0x00007fb7d496b574 in maxminddb_free_storage (object=0x2729ea8) at /usr/src/debug/MaxMind-DB-Reader-php-cbd695a5309c15249ef5944997cfb71f2a8a7963/ext/maxminddb.c:418
    #2  0x00000000005e4aac in zend_objects_store_del_ref_by_handle_ex (handle=3100, handlers=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_objects_API.c:226
    #3  0x00000000005db4b8 in gc_collect_cycles () at /usr/src/debug/php-5.5.19/Zend/zend_gc.c:834
    #4  0x00000000005db8b4 in gc_zval_possible_root (zv=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_gc.c:166
    #5  0x0000000000641b9e in gc_zval_check_possible_root (execute_data=0x7fb7e6b63898) at /usr/src/debug/php-5.5.19/Zend/zend_gc.h:183
    #6  i_zval_ptr_dtor (execute_data=0x7fb7e6b63898) at /usr/src/debug/php-5.5.19/Zend/zend_execute.h:90
    #7  ZEND_ASSIGN_SPEC_CV_VAR_HANDLER (execute_data=0x7fb7e6b63898) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:36980
    #8  0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b63898) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #9  0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b63898) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #10 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b63380) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #11 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b63380) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #12 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b63380) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #13 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b62c48) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #14 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b62c48) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #15 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b62c48) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #16 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b62500) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #17 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b62500) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #18 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b62500) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #19 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b62138) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #20 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b62138) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #21 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b62138) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #22 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b61a60) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #23 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b61a60) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #24 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b61a60) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #25 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b61718) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #26 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b61718) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #27 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b61718) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #28 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b61450) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #29 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b61450) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #30 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b61450) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #31 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b61328) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #32 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b61328) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #33 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b61328) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #34 0x00000000005ae4dc in zend_call_function (fci=0x7fffd1547660, fci_cache=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_execute_API.c:937
    #35 0x00000000004f11a8 in zif_array_map (ht=<value optimized out>, return_value=0x33a1720, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/ext/standard/array.c:4371
    #36 0x00000000005ab319 in dtrace_execute_internal (execute_data_ptr=<value optimized out>, fci=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:97
    #37 0x000000000063d662 in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:552
    #38 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b61060) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #39 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b61060) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #40 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b60dc0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #41 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b60dc0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #42 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b60dc0) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #43 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b60c70) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #44 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b60c70) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #45 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b60c70) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #46 0x00000000005ae4dc in zend_call_function (fci=0x7fffd1547d90, fci_cache=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_execute_API.c:937
    #47 0x00000000004fe7e7 in zif_call_user_func_array (ht=<value optimized out>, return_value=0x33abce0, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/ext/standard/basic_functions.c:4806
    #48 0x00000000005ab319 in dtrace_execute_internal (execute_data_ptr=<value optimized out>, fci=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:97
    #49 0x000000000063d662 in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:552
    #50 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b608e0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #51 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b608e0) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #52 0x00000000005ae4dc in zend_call_function (fci=0x7fffd1548170, fci_cache=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_execute_API.c:937
    #53 0x00000000005d36f7 in zend_call_method (object_pp=0x7fffd1548298, obj_ce=<value optimized out>, fn_proxy=0x21a4908, function_name=0x6cc3f6 "__call", function_name_len=<value optimized out>, retval_ptr_ptr=0x7fffd15482a8, param_count=2, arg1=0x33ab198, arg2=0x33abe88) at /usr/src/debug/php-5.5.19/Zend/zend_interfaces.c:97
    #54 0x00000000005e23ed in zend_std_call_user_call (ht=<value optimized out>, return_value=0x33b3a30, return_value_ptr=<value optimized out>, this_ptr=0x30992b0, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_object_handlers.c:899
    #55 0x00000000005ab319 in dtrace_execute_internal (execute_data_ptr=<value optimized out>, fci=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:97
    #56 0x000000000063d662 in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:552
    #57 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b60768) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #58 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b60768) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #59 0x00000000005ae4dc in zend_call_function (fci=0x7fffd1548620, fci_cache=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_execute_API.c:937
    #60 0x00000000004b96b6 in zim_reflection_method_invokeArgs (ht=<value optimized out>, return_value=0x33a9aa0, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/ext/reflection/php_reflection.c:3018
    #61 0x00000000005ab319 in dtrace_execute_internal (execute_data_ptr=<value optimized out>, fci=<value optimized out>, return_value_used=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:97
    #62 0x000000000063d662 in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:552
    #63 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b604b0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #64 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b604b0) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #65 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5fec8) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #66 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5fec8) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #67 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5fec8) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #68 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5f6b0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #69 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5f6b0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #70 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5f6b0) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #71 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5f1b8) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #72 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5f1b8) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #73 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5f1b8) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #74 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5ec38) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #75 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5ec38) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #76 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5ec38) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #77 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5e640) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #78 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5e640) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #79 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5e640) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #80 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5dfb8) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #81 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5dfb8) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #82 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5dfb8) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #83 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5d768) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #84 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5d768) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #85 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5d768) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #86 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5d0d0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #87 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5d0d0) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #88 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5d0d0) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #89 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5ca18) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #90 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5ca18) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #91 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5ca18) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #92 0x000000000063dd50 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fb7e6b5c480) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:584
    #93 0x000000000062f138 in execute_ex (execute_data=0x7fb7e6b5c480) at /usr/src/debug/php-5.5.19/Zend/zend_vm_execute.h:363
    #94 0x00000000005ab44e in dtrace_execute_ex (execute_data=0x7fb7e6b5c480) at /usr/src/debug/php-5.5.19/Zend/zend_dtrace.c:73
    #95 0x00000000005ba44c in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/debug/php-5.5.19/Zend/zend.c:1330
    #96 0x000000000055a8b0 in php_execute_script (primary_file=0x7fffd154be70) at /usr/src/debug/php-5.5.19/main/main.c:2506
    #97 0x000000000066bbe3 in do_cli (argc=3, argv=0xebdcc0) at /usr/src/debug/php-5.5.19/sapi/cli/php_cli.c:994
    #98 0x000000000066c3e8 in main (argc=3, argv=0xebdcc0) at /usr/src/debug/php-5.5.19/sapi/cli/php_cli.c:1378
    
    opened by thias 5
  • Please include the examples and tests in the release tarball

    Please include the examples and tests in the release tarball

    Hi, I'm creating a Gentoo package for MaxMind-DB-Reader-php, and the examples and tests would be useful for us. The examples get installed globally, and we have the option to run the tests before installation to make sure that everything works as expected (before, say, proceeding with an upgrade).

    opened by orlitzky 12
  • Unable to locate maxminddb.h in custom installation

    Unable to locate maxminddb.h in custom installation

    I'm trying ton install php + maxmind-db-reader in a custom path: --prefix=/home/geoip/usr

    1. Install php-7.1.0 (success)
    2. Install libmaxminddb-1.2.0 (success)
    3. Install maxmind-db-reader-php-1.1.2 (error) /home/geoip/source/php/maxmind-db-reader-php-1.1.2/MaxMind-DB-Reader-php-master/ext/maxminddb.c:23:23: fatal error: maxminddb.h: No such file or directory #include <maxminddb.h>

    Here are the step by step in a fresh debian 8.7.1 installation http://pastebin.com/0W2QCehx

    When i try to install libmaxmind and maxmind-db-reader-php without --prefix=/home/geoip/usr works ok. But I want everything related to this installation to be located in /home/geoip/usr.

    I also tried:

    ./configure \
    	--includedir=/home/geoip/usr/include \
    	--with-maxminddb \
    	--with-php-config=/home/geoip/usr/bin/php-config
    

    Same error. My guess I'm not setting path correctly or ./configure is not using --prefix or --includedir correctly.

    bug 
    opened by leo020588 4
  • Persistent connection

    Persistent connection

    Most often use case in PHP is to detect a country/city of current request's IP address. In common fpm/fastcgi environment database file is re-opened and re-read on each and every request when MaxMind\Db\Reader instance is created. The idea is to keep database file opened as long as php fpm/fastcgi master process is alive. Simple tests show performance gain at least by an order of magnitude. As as side note, database should be reloaded whenever its file size or timestamp has changed.

    enhancement 
    opened by 5lava 2
  • Provide package in PPA

    Provide package in PPA

    https://github.com/maxmind/libmaxminddb is avialable from ppa:maxmind/ppa but this package is not. Is it possible to add this package to the PPA so that we don't need to manually compile it?

    enhancement 
    opened by joshuaspence 5
  • C extension should be configured via INI

    C extension should be configured via INI

    It would be nice for it to be possible to set C extension's default database path in INI file, to allow system wide configuration for the extension, as it was done for the old extension.

    enhancement 
    opened by Addvilz 1
Releases(v1.11.0)
  • v1.11.0(Oct 18, 2021)

    • Replace runtime define of a constant to facilitate opcache preloading. Reported by vedadkajtaz. GitHub #134.
    • Resolve minor issue found by the Clang static analyzer in the C extension.
    Source code(tar.gz)
    Source code(zip)
  • v1.10.1(Apr 14, 2021)

    • Fix a TypeError exception in the pure PHP reader when using large databases on 32-bit PHP builds with the bcmath extension. Reported by dodo1708. GitHub #124.
    Source code(tar.gz)
    Source code(zip)
  • v1.10.0(Feb 9, 2021)

    • When using the pure PHP reader, unsigned integers up to PHP_MAX_INT will now be integers in PHP rather than strings. Previously integers greater than 2^24 on 32-bit platforms and 2^56 on 64-bit platforms would be strings due to the use of gmp or bcmath to decode them. Reported by Alejandro Celaya. GitHub #119.
    Source code(tar.gz)
    Source code(zip)
  • v1.9.0(Jan 7, 2021)

  • v1.8.0(Oct 1, 2020)

  • v1.7.0(Aug 7, 2020)

    • IMPORTANT: PHP 7.2 or greater is now required.
    • The extension no longer depends on the pure PHP classes in maxmind-db/reader. You can use it independently.
    • Type hints have been added to both the pure PHP implementation and the extension.
    • The metadata method on the reader now returns a new copy of the metadata object rather than the actual object used by the reader.
    • Work around PHP is_readable() bug. Reported by Ben Roberts. GitHub #92.
    • This is the first release of the extension as a PECL package. GitHub #34.
    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Dec 19, 2019)

    • 1.5.0 and 1.5.1 contained a possible memory corruptions when using getWithPrefixLen. This has been fixed. Reported by proton-ab. GitHub #96.
    • The composer.json file now conflicts with all versions of the maxminddb C extension less than the Composer version. This is to reduce the chance of having an older, conflicting version of the extension installed. You will need to upgrade the extension before running composer update. Pull request by Benoît Burnichon. GitHub #97.
    Source code(tar.gz)
    Source code(zip)
  • v1.5.1(Dec 12, 2019)

    • Minor performance improvements.
    • Make tests pass with older versions of libmaxminddb. PR by Remi Collet. GitHub #90.
    • Test enhancements. PR by Chun-Sheng, Li. GitHub #91.
    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Sep 30, 2019)

    • PHP 5.6 or greater is now required.
    • The C extension now supports PHP 8. Pull request by John Boehr. GitHub #87.
    • A new method, getWithPrefixLen, was added to the Reader class. This method returns an array containing the record and the prefix length for that record. GitHub #89.
    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Jan 4, 2019)

    • The maxminddb extension now returns a string when a uint32 value is greater than LONG_MAX. Previously, the value would overflow. This generally only affects 32-bit machines. Reported by Remi Collet. GitHub #79.
    • For uint64 values, the maxminddb extension now returns an integer rather than a string when the value is less than or equal to LONG_MAX. This more closely matches the behavior of the pure PHP reader.
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Nov 20, 2018)

    • The maxminddb extension now has the arginfo when using reflection. PR by Remi Collet. GitHub #75.
    • The maxminddb extension now provides MINFO() function that displays the extension version and the libmaxminddb version. PR by Remi Collet. GitHub #74.
    • The maxminddb configure script now uses pkg-config when available to get libmaxmindb build info. PR by Remi Collet. GitHub #73.
    • The pure PHP reader now correctly decodes integers on 32-bit platforms. Previously, large integers would overflow. Reported by Remi Collet. GitHub #77.
    • There are small performance improvements for the pure PHP reader.
    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Feb 21, 2018)

    • IMPORTANT: The maxminddb extension now obeys open_basedir. If open_basedir is set, you must store the database within the specified directory. Placing the file outside of this directory will result in an exception. Please test your integration before upgrading the extension. This does not affect the pure PHP implementation, which has always had this restriction. Reported by Benoît Burnichon. GitHub #61.
    • A custom autoload.php file is provided for installations without Composer. GitHub #56.
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Oct 27, 2017)

    • PHP 5.4 or greater is now required.
    • The Reader class for the maxminddb extension is no longer final. This was change to match the behavior of the pure PHP class. Reported and fixed by venyii. GitHub #52 & #54.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.3(Jan 19, 2017)

  • v1.1.2(Nov 22, 2016)

    • Searching for database metadata only occurs within the last 128KB (128 * 1024 bytes) of the file, speeding detection of corrupt datafiles. Reported by Eric Teubert. GitHub #42.
    • Suggest relevant extensions when installing with Composer. GitHub #37.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Sep 15, 2016)

    • Development files were added to the .gitattributes as export-ignore so that they are not part of the Composer release. Pull request by Michele Locati. GitHub #39.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jan 4, 2016)

  • v1.0.3(Mar 13, 2015)

  • v1.0.2(Jan 19, 2015)

    • Previously the MaxMind DB extension would cause a segfault if the Reader object's destructor was called without first having called the constructor. (Reported by Matthias Saou & Juan Peri. GitHub #20.)
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Jan 12, 2015)

    • In the last several releases, the version number in the extension was incorrect. This release is being done to correct it. No other code changes are included.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Dec 19, 2014)

    • First production release.
    • In the pure PHP reader, a string length test after fread() was replaced with the difference between the start pointer and the end pointer. This provided a 15% speed increase.
    Source code(tar.gz)
    Source code(zip)
  • v0.3.3(Sep 15, 2014)

  • v0.3.2(Sep 10, 2014)

    • Fixed invalid reference to global class RuntimeException from namespaced code. Fixed by Steven Don. GitHub issue #15.
    • Additional documentation of Metadata class as well as misc. documentation cleanup.
    Source code(tar.gz)
    Source code(zip)
  • v0.3.1(May 1, 2014)

    • The API now works when mbstring.func_overload is set.
    • BCMath is no longer required. If the decoder encounters a big integer, it will try to use GMP and then BCMath. If both of those fail, it will throw an exception. No databases released by MaxMind currently use big integers.
    • The API now officially supports HHVM when using the
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Feb 19, 2014)

    • This API is now licensed under the Apache License, Version 2.0.
    • The code for the C extension was cleaned up, fixing several potential issues.
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Oct 21, 2013)

    • Added optional C extension for using libmaxminddb in place of the pure PHP reader.
    • Significantly improved error handling in pure PHP reader.
    • Improved performance for IPv4 lookups in an IPv6 database.
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Jul 16, 2013)

Owner
MaxMind
MaxMind
A simple program to query mysql data and display the queried data in JSON format

A simple program to query mysql data and display the queried data in JSON format. The data displayed in JSON format will change and update as the data in your mysql database changes.

null 2 Mar 7, 2022
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

SleekwareDB 12 Dec 11, 2022
The lightweight PHP database framework to accelerate development

The lightweight PHP database framework to accelerate development Features Lightweight - Less than 100 KB, portable with only one file Easy - Extremely

Angel Lai 4.6k Dec 28, 2022
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

CakePHP 4.3k Jan 7, 2023
Database management in a single PHP file

Adminer - Database management in a single PHP file Adminer Editor - Data manipulation for end-users https://www.adminer.org/ Supports: MySQL, MariaDB

Jakub Vrána 5.5k Jan 1, 2023
A php class for managing and connecting to a database

Query builder class php This class is responsible for creating and executing sql commands and helps you to execute as easily as possible and safely. I

Mohammad Qasemi 39 Dec 11, 2022
Database lookup tool in php, skidlookup has not been claimed so if u want to use this src all right's go to u, idea came from fedsearch

skidlookup Database lookup tool in php, skidlookup has not been claimed so if u want to use this src, all right's go to u, idea came from fedsearch in

Nano 12 Dec 1, 2021
A complete, simple and powerful database framework written in PHP

BaseSQL BaseSQL is a complete database framework written in PHP. It was built to accelerate projects development by handle database connections and qu

Willian Pinheiro 2 Sep 21, 2021
Connect and work with MySQL/MariaDB database through MySQLi in PHP. This is an introductory project, If you need a simple and straightforward example that takes you straight to the point, you can check out these examples.

First MySQLi PHP Connect and work with MySQL/MariaDB database through MySQLi in PHP. The above exercises are designed for students. This is an introdu

Max Base 4 Feb 22, 2022
Database lookup tool in php, skidlookup has not been claimed so if u want to use this src all right's go to u, idea came from fedsearch

skidlookup Database lookup tool in php, skidlookup has not been claimed so if u want to use this src, all right's go to u, idea came from fedsearch in

Nano 12 Dec 1, 2021
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7

Maghead 4.0.x IS CURRENTLY UNDER HEAVY DEVELOPMENT, API IS NOT STABLE Maghead is an open-source Object-Relational Mapping (ORM) designed for PHP7. Mag

Maghead 477 Dec 24, 2022
phpSleekDBAdmin - a web-based SleekDB database admin tool written in PHP

phpSleekDBAdmin is a web-based SleekDB database admin tool written in PHP. Following in the spirit of the flat-file system used by SleekDB, phpSleekDBAdmin consists of a single source file, phpsleekdbadmin.php. The interface and user experience is comparable to that of phpLiteAdmin and phpMyAdmin.

GalAnonym 8 Oct 26, 2022
PHP application-level database locking mechanisms to implement concurrency control patterns.

PHP DB Locker Introduction PHP application-level database locking mechanisms to implement concurrency control patterns. Supported drivers: Postgres In

cybercog 3 Sep 29, 2022
A simple library for managing database connections, results pagination and building queries in PHP

PHP lions-software-database-manager This is a simple library for managing database connections, results pagination and building queries in PHP. Esta é

Lions Software 0 Feb 7, 2022
The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

Mark Armendariz 0 Jan 7, 2022
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

The Laravel Components 2.5k Dec 27, 2022
ORM layer that creates models, config and database on the fly

RedBeanPHP 5 RedBeanPHP is an easy to use ORM tool for PHP. Automatically creates tables and columns as you go No configuration, just fire and forget

Gabor de Mooij 2.2k Jan 9, 2023
Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer

Spot DataMapper ORM v2.0 Spot v2.x is built on the Doctrine DBAL, and targets PHP 5.4+. The aim of Spot is to be a lightweight DataMapper alternative

Spot ORM 602 Dec 27, 2022
SQL database access through PDO.

Aura.Sql Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO,

Aura for PHP 533 Dec 30, 2022