Git Product home page Git Product logo

maxmind-db-reader-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maxmind-db-reader-php's Issues

PHP7 support

I got an error after installation

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/maxminddb.so' - /usr/lib/php/20151012/maxminddb.so: undefined symbol: zval_used_for_init in Unknown on line 0

Any suggestion?
PHP 7.0.6

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

Extension compiles, but does not appear to be loaded.

I am using Ubuntu 13.10 64-bit and PHP 5.5.7.

I have compiled and installed libmaxminddb and then compiled the master of the C extension.

I have enabled it in my php.ini, but upon restarting PHP, I do not see anything in phpinfo(). Phpinfo() does show that the .ini file to enable the extension has been loaded, however.

A look in the logs do not show any errors either.

get model by other properties than IP

Hi It would be great if we can get the country or city model for example by Iso code, country name, etc
It's possible? I tried to look the code by I get lost in findAddressInTree :(

Addendum to installation instructions

I've installed libmaxminddb and this PHP extension using the described installations from git clone.
It did not work; PHP could not find libmaxminddb.so.0 from the maxminddb.so extension.

Turns out maxminddb.so was installed in /usr/lib64/php/modules, whereas libmaxminddb.so.0 was in /usr/local/lib.

The fix to this was to adjust the last step from ldconfig to ldconfig /usr/local/lib.

It might be a good idea to add this fix to the README file.

The server in question was running 64bit Centos 6.x.

[INFO] RPM packages

Not an issue ;) for your information

php-maxminddb packages are now available in fedora official repository

See https://apps.fedoraproject.org/packages/php-maxminddb

Fedora users can simply install it with

dnf install php-maxminddb
CentOS / RHEL 7 users, after enabling EPEL repostiory, with

yum install php-maxminddb

Perhaps worth something in the README.md file.

P.S. also available in my repository for other PHP versions

Having trouble in getting it to work properly

Hi everyone,

I'm having some trouble in setting this up with Laravel 5.1 on a live server, I'm always getting the output below. I've required Laravel-GeoIP (https://github.com/Torann/laravel-geoip/) to my Laravel project, but now the problem is with MaxMind-DB-Reader-php.

I've followed the instructions of the README, but still nothing.

Any help would be appreciated. Thanks.

RuntimeException in Decoder.php line 259:
The gmp or bcmath extension must be installed to read this database.
in Decoder.php line 259
at Decoder->decodeBigUint('V9=�', '4') in Decoder.php line 132
at Decoder->decodeByType('uint64', '38296851', '4') in Decoder.php line 98
at Decoder->decode('38296849') in Decoder.php line 194
at Decoder->decodeMap('9', '38296778') in Decoder.php line 105
at Decoder->decodeByType('map', '38296778', '9') in Decoder.php line 98
at Decoder->decode('38296777') in Reader.php line 65
at Reader->__construct('/var/www/ubicoding/frontend/releases/20151104205426/storage/app/geoip.mmdb') in Reader.php line 52
at Reader->__construct('/var/www/ubicoding/frontend/releases/20151104205426/storage/app/geoip.mmdb') in GeoIP.php line 181
at GeoIP->locate_maxmind('84.90.35.43') in GeoIP.php line 158
at GeoIP->find(null) in GeoIP.php line 119
at GeoIP->getLocation() in Facade.php line 211
at Facade::__callStatic('getLocation', array()) in StatisticsLibrary.php line 33
at GeoIPFacade::getLocation() in StatisticsLibrary.php line 33
at StatisticsLibrary::addStatistic(null, 'public', 'show', 'home') in HomeController.php line 32
at HomeController->index()
at call_user_func_array(array(object(HomeController), 'index'), array()) in Controller.php line 256
at Controller->callAction('index', array()) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(HomeController), object(Route), 'index') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(HomeController), object(Route), object(Request), 'index') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\HomeController', 'index') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 55

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?

cant make

 cc -I. -I/root/MaxMind-DB-Reader-php/ext -DPHP_ATOM_INC -I/root/MaxMind-DB-Reader-php/ext/include -I/root/MaxMind-DB-Reader-php/ext/main -I/root/MaxMind-DB-Reader-php/ext -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/include/x86_64-linux-gnu -DHAVE_CONFIG_H -g -O2 -c /root/MaxMind-DB-Reader-php/ext/maxminddb.c  -fPIC -DPIC -o .libs/maxminddb.o
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:153:51: error: macro "ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX" requires 6 arguments, but only 5 given
     arginfo_maxminddbreader_get, 0, 1, IS_MIXED, 1)
                                                   ^
In file included from /usr/local/include/php/Zend/zend_interfaces.h:25,
                 from /root/MaxMind-DB-Reader-php/ext/php_maxminddb.h:14,
                 from /root/MaxMind-DB-Reader-php/ext/maxminddb.c:14:
/usr/local/include/php/Zend/zend_API.h:105:70: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, NULL, type_hint, pass_by_ref, allow_null, 0 },
                                                                      ^
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:154:1: note: in expansion of macro 'ZEND_ARG_TYPE_INFO'
 ZEND_ARG_TYPE_INFO(0, ip_address, IS_STRING, 0)
 ^~~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:105:124: error: expected identifier or '(' before ',' token
 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, NULL, type_hint, pass_by_ref, allow_null, 0 },
                                                                                                                            ^
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:154:1: note: in expansion of macro 'ZEND_ARG_TYPE_INFO'
 ZEND_ARG_TYPE_INFO(0, ip_address, IS_STRING, 0)
 ^~~~~~~~~~~~~~~~~~
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:163:64: error: macro "ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX" requires 6 arguments, but only 5 given
     arginfo_maxminddbreader_getWithPrefixLen, 0, 1, IS_ARRAY, 1)
                                                                ^
In file included from /usr/local/include/php/Zend/zend_interfaces.h:25,
                 from /root/MaxMind-DB-Reader-php/ext/php_maxminddb.h:14,
                 from /root/MaxMind-DB-Reader-php/ext/maxminddb.c:14:
/usr/local/include/php/Zend/zend_API.h:105:70: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, NULL, type_hint, pass_by_ref, allow_null, 0 },
                                                                      ^
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:164:1: note: in expansion of macro 'ZEND_ARG_TYPE_INFO'
 ZEND_ARG_TYPE_INFO(0, ip_address, IS_STRING, 0)
 ^~~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:105:124: error: expected identifier or '(' before ',' token
 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, NULL, type_hint, pass_by_ref, allow_null, 0 },
                                                                                                                            ^
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:164:1: note: in expansion of macro 'ZEND_ARG_TYPE_INFO'
 ZEND_ARG_TYPE_INFO(0, ip_address, IS_STRING, 0)
 ^~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/php/Zend/zend_interfaces.h:25,
                 from /root/MaxMind-DB-Reader-php/ext/php_maxminddb.h:14,
                 from /root/MaxMind-DB-Reader-php/ext/maxminddb.c:14:
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:579:36: error: 'arginfo_maxminddbreader_get' undeclared here (not in a function); did you mean 'arginfo_maxminddbreader_void'?
     PHP_ME(MaxMind_Db_Reader, get, arginfo_maxminddbreader_get,  ZEND_ACC_PUBLIC)
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:70:75: note: in definition of macro 'ZEND_FENTRY'
 #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
                                                                           ^~~~~~~~
/usr/local/include/php/main/php.h:363:25: note: in expansion of macro 'ZEND_ME'
 #define PHP_ME          ZEND_ME
                         ^~~~~~~
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:579:5: note: in expansion of macro 'PHP_ME'
     PHP_ME(MaxMind_Db_Reader, get, arginfo_maxminddbreader_get,  ZEND_ACC_PUBLIC)
     ^~~~~~
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:580:49: error: 'arginfo_maxminddbreader_getWithPrefixLen' undeclared here (not in a function); did you mean 'zim_MaxMind_Db_Reader_getWithPrefixLen'?
     PHP_ME(MaxMind_Db_Reader, getWithPrefixLen, arginfo_maxminddbreader_getWithPrefixLen,  ZEND_ACC_PUBLIC)
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:70:75: note: in definition of macro 'ZEND_FENTRY'
 #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
                                                                           ^~~~~~~~
/usr/local/include/php/main/php.h:363:25: note: in expansion of macro 'ZEND_ME'
 #define PHP_ME          ZEND_ME
                         ^~~~~~~
/root/MaxMind-DB-Reader-php/ext/maxminddb.c:580:5: note: in expansion of macro 'PHP_ME'
     PHP_ME(MaxMind_Db_Reader, getWithPrefixLen, arginfo_maxminddbreader_getWithPrefixLen,  ZEND_ACC_PUBLIC)
     ^~~~~~
make: *** [Makefile:194: maxminddb.lo] Error 1

PHP 7 Support

Is the extension compatible with PHP7? If not, is there any immediate plans to update it to support the new version?

Reader does not decode GeoIP2-Anonymous-IP DB

require_once 'vendor/autoload.php';
use MaxMind\Db\Reader;

$ipAddress = '8.8.8.8';
$databaseFile = 'GeoIP2-Anonymous-IP.mmdb';

$reader = new Reader($databaseFile);
print_r($reader->get($ipAddress));
$reader->close();

Output is empty array
Array
(
)

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.

Cannot compile the extension

Hello,

When trying to compile the extension I get the following error:

MaxMind-DB-Reader-php-master/ext/maxminddb.c:22:23: fatal error: maxminddb.h: No such file or directory
compilation terminated.
make: *** [maxminddb.lo] Error 1

Steps to reproduce:

  1. Download the latest code from master
  2. cd ext
  3. phpize
  4. ./configure
  5. make

I'm using PHP 5.5.5.

Test failures on 32-bit

Everything OK on 64-bit

On 32-bit (yes this still exists...)

There were 4 failures:
1) MaxMind\Db\Test\Reader\DecoderTest::testPointers
decoded pointers - 1
Failed asserting that -1 is identical to 4294967295.0.
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:371
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:349
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:307
2) MaxMind\Db\Test\Reader\DecoderTest::testUint32
decoded uint32 - 1
Failed asserting that -1 is identical to 4294967295.0.
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:371
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:349
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:322
3) MaxMind\Db\Test\Reader\DecoderTest::testUint64
decoded uint64 - 1
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-4294967295
+-1
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:371
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:338
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:327
4) MaxMind\Db\Test\Reader\DecoderTest::testUint128
decoded uint128 - 1
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-4294967295
+-1
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:371
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:338
/builddir/build/BUILD/MaxMind-DB-Reader-php-e042b4f8a2dff41e19019faf16427178b07fbd58/tests/MaxMind/Db/Test/Reader/DecoderTest.php:332
FAILURES!

mbstring overloading issue

hi,
when str* functions are overloaded with mb_* counterparts software stop working, like this

PHP Fatal error:  Uncaught exception 'MaxMind\Db\Reader\InvalidDatabaseException' with message 'The MaxMind DB file's data section contains bad data (unknown data type or corrupt data)' in /root/geo-ip/MaxMind-DB-Reader-php-master/src/MaxMind/Db/Reader/Decoder.php:275
Stack trace:
#0 /root/geo-ip/MaxMind-DB-Reader-php-master/src/MaxMind/Db/Reader/Decoder.php(106): MaxMind\Db\Reader\Decoder->read(29478887, 13)
#1 /root/geo-ip/MaxMind-DB-Reader-php-master/src/MaxMind/Db/Reader/Decoder.php(91): MaxMind\Db\Reader\Decoder->decodeByType('double', 29478887, 13)
#2 /root/geo-ip/MaxMind-DB-Reader-php-master/src/MaxMind/Db/Reader.php(63): MaxMind\Db\Reader\Decoder->decode(29478886)
#3 /root/geo-ip/MaxMind-DB-Reader-php-master/src/1.php(26): MaxMind\Db\Reader->__construct('GeoLite2-City.m...')
#4 {main}
  thrown in /root/geo-ip/MaxMind-DB-Reader-php-master/src/MaxMind/Db/Reader/Decoder.php on line 275

there is a patch to resolve the issue

diff -r src/MaxMind/Db/Reader/Decoder.php mod/MaxMind/Db/Reader/Decoder.php
271c271
<             if (strlen($value) === $numberOfBytes) {

---
>             if (\MaxMind\Db\strlen($value) === $numberOfBytes) {
diff -r src/MaxMind/Db/Reader.php mod/MaxMind/Db/Reader.php
8a9,14
> if( \strlen("俄罗斯") == 3 ) {
>     function strlen(&$s) { return \mb_strlen($s,'8bit'); }
> }
> else {
>     function strlen(&$s) { return \strlen($s); }
> }
216c222
<             if (strlen($value) === $numberOfBytes) {

---
>             if (\MaxMind\Db\strlen($value) === $numberOfBytes) {
250c256
<         $markerLength = strlen($marker);

---
>         $markerLength = \MaxMind\Db\strlen($marker);

thanks

Caching options

Hello,

Thanks for this awesome library.
I'd like to see more caching options to accelerate lookup speed like caching the database file into memory using shmop PHP extension.

Thanks

Consider adding an autoloader (or 'require' statements)

I see that there's an open issue #34 to create a PECL package. To do that, you'll have to eliminate the dependency on composer, which would also help us create a Gentoo package. And to eliminate the dependency on composer, you'll need to either

  • Ship your own autoload.php, so that composer isn't needed to generate it.
  • Add back the few missing require statements. Since there are so few files in the library, this one makes more sense than a custom autoloader to me.

Either of those would also simplify the documentation, and let people run the tests from a git clone.

We can work around the issue with https://github.com/php-fedora/autoloader, but like they say, it would be nice if we didn't have to =)

TypeError in Db\Reader\Decoder with bcmath extension

Desription

When reading from the database, I get the following error message:
bcadd() expects parameter 1 to be string, int given

Error location: src/MaxMind/Db/Reader/Decoder.php:296

Reproduce

  • used database type: ISP
  • looked up IP-Address: 195.66.12.14
  • GeoIP2 version: v2.11.0

Proposed fix

Instead of

$pointer = bcadd($pointerOffset, (string) $this->pointerBase);

use

$pointer = (int) bcadd((string) $pointerOffset, (string) $this->pointerBase);

First Argument has to be string (but is int) and return value needs to be int (required in decode line 76)

Minor performance improvement suggestion

While trying to determine why BCMath is required, I noticed that decodeBigUint() repeatedly runs the calculation:

bcpow(2, 32)

Is there any particular reason that the result of expensive calculations aren't cached somewhere?

Class MaxMind\Db\Reader\InvalidDatabaseException not found

I'm using the C extension and able to perform lookups using \MaxMind\Db\Reader just fine when there's no exceptions. But if the database file is invalid (corrupted or missing), it fails to throw the MaxMind\Db\Reader\InvalidDatabaseException because the class is not defined.

try {
    $geo = new MaxMind\Db\Reader('path/to/corrupted/file.mmdb');
} catch (MaxMind\Db\Reader\InvalidDatabaseException $ex) {
    echo 'expected result!';
}

Instead of echoing 'expected result!', a PHP fatal error occurs: ' Fatal error: Class MaxMind\Db\Reader\InvalidDatabaseException not found in ...'.

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?

Bad design of Reader: constructor is too heavy

It's bad really bad idea to perform excessive operations (opening big files, building large metadata trees etc.) in constructor - constructors should be as simple as possible.
Current design is so bad that it can't be used e.g. as a service in frameworks which use autowiring. One first needs to implement a proxy around the reader to defer loading the file. If not, the db file would be opened and read each time the instance is created, even if it's not actually used.
As a (temporary) solution I currently use a proxy wrapper around GeoIp2\Database\Reader which defers call to parent::__construct() until any of its methods is first called.

C extension does not support Reflection?

Take the following code:

$rm1 = new \ReflectionMethod('MaxMind\Db\Reader', '__construct');
$rm2 = new \ReflectionMethod('MaxMind\Db\Reader', 'get');

var_dump($rm1->getParameters());
var_dump($rm2->getParameters());

For the PHP library this will output:

array(1) {
  [0] =>
  class ReflectionParameter#5 (1) {
    public $name =>
    string(8) "database"
  }
}

array(1) {
  [0] =>
  class ReflectionParameter#5 (1) {
    public $name =>
    string(9) "ipAddress"
  }
}

But for the C extension:

array(0) {
}

array(0) {
}

This throws off static analyzers like https://github.com/phpstan/phpstan which rely on that information and throw errors (Class MaxMind\Db\Reader constructor invoked with 1 parameter, 0 required.) since you're passing a parameter to a method that seemingly does not take any parameters.

This came up when running PHPStan in the CI env with the C extension installed, for now I exclude the test that calls the Reader class, but if it isn't too much trouble to support this, I'd be happy :)

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.

undefined symbol: zval_used_for_init

I am getting the following error when trying to load maxminddb.so into PHP 7. What is wrong?

Warning: PHP Startup: Unable to load dynamic library '/opt/cpanel/ea-php70/root/usr/lib64/php/modules/maxminddb.so' - /opt/cpanel/ea-php70/root/usr/lib64/php/modules/maxminddb.so: undefined symbol: zval_used_for_init in Unknown on line 0

http://pastebin.com/RN1gPpQn

extension does not care about open_basedir

if (0 != access(db_file, R_OK)) {

Access is a very low level file operation. Not all low level accesses to database files should be authorized.
Going from Userland php to extension is no issue, but the reverse could cause some open_basedir errors. Database path could be passed from userland (so can sometimes be accessed by attackers) so internal path access php checks are mandatory.

[1.4.0] Test failure on 32-bit

Test suite ok without the extension

With the extension

There was 1 failure:
1) MaxMind\Db\Test\Reader\ReaderTest::testDecoder
Failed asserting that 268435456 is identical to '268435456'.
/builddir/build/BUILD/MaxMind-DB-Reader-php-2f1086e38939e808cc23b17daa469da094af9125/tests/MaxMind/Db/Test/ReaderTest.php:57
FAILURES!

Add tag for v1.7.0

Hi,
Thanks for all the changes included in 1.7.0! Can you please tag a release for it? Right now the last tagged release is 1.6.0

Regards,
Olivier

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

How to get Routing Prefix (CIDR) ?

I'm using GeoLite2-City.mmdb file.

I'm using following code:

require_once('MaxMind-DB-Reader-php/autoload.php');
use MaxMind\Db\Reader;
$reader = new Reader('GeoLite2-City.mmdb');
$record = $reader->get($ip);

I'm getting $record as:

Array
(
    [city] => Array
        (
            [geoname_id] => 1275339
            [names] => Array
                (
                    [de] => Mumbai
                    [en] => Mumbai
                    [es] => Bombay
                    [fr] => Bombay
                    [ja] => ムン�イ
                    [pt-BR] => Mumbai
                    [ru] => Мумбаи
                    [zh-CN] => å­Ÿä¹°
                )

        )

other data of [continent] , [country] , [location] , [subdivisions]

)

How do I get the CIDR notation of the IP address from the .mmdb file?

Reader::findMetadataStart runs forever on faulty files

If the database file is faulty, findMetadataStart has to go through the whole file byte by byte, which is extremely slow and creates a timeout exception (for servers with default config of 30 seconds timeout).

I know I can (and probably should) check for the validity of the database file before using the reader. However, it would be nice if it could handle that case more gracefully.

Discrepancy in PHP library and C extension: Reader class marked `final`

The Reader class in the C extension is marked final (from what I understand):
https://github.com/maxmind/MaxMind-DB-Reader-php/blob/master/ext/maxminddb.c#L538

And the PHP library is not:
https://github.com/maxmind/MaxMind-DB-Reader-php/blob/master/src/MaxMind/Db/Reader.php#L14

This just came up while developing locally without the C extension and then running the tests in the CI env with the C extension installed which produces different results, for example when mocking the Reader class which will fail in the CI env.

How can you tell if the C extension is used?

I thought that I could remove the maxmind-db/reader package with composer after having installed the C extension.

I'm too dumb with composer to do that. In the php info, I have the following:

MaxMind DB Reader enabled
maxminddb extension version 1.4.1
libmaxminddb library version 1.3.2

it seems to be a good indication that the C extension is used and not the PHP code. Would you agree?

Install issues

Hi,

I am trying to install the C library for the reader class and am getting errors. Not sure where to go from here, please assist.

root@web001:/home/offerit/offerit/vendor/maxmind-db/reader/ext# ./configure CXXFLAGS="/usr/local/include/maxminddb.h"
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20170718
checking for PHP installed headers prefix... /usr/include/php/20170718
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking Whether to enable the MaxMind DB Reader extension... yes, shared
checking for MaxMind DB debug support... no
checking for MMDB_open in -lmaxminddb... yes
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/x86_64-linux-gnu-ld
checking if the linker (/usr/bin/x86_64-linux-gnu-ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/x86_64-linux-gnu-ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/x86_64-linux-gnu-ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
root@web001:/home/offerit/offerit/vendor/maxmind-db/reader/ext# make
/bin/bash /home/offerit/offerit/vendor/maxmind-db/reader/ext/libtool --mode=compile cc  -I. -I/home/offerit/offerit/vendor/maxmind-db/reader/ext -DPHP_ATOM_INC -I/home/offerit/offerit/vendor/maxmind-db/reader/ext/include -I/home/offerit/offerit/vendor/maxmind-db/reader/ext/main -I/home/offerit/offerit/vendor/maxmind-db/reader/ext -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c -o maxminddb.lo
libtool: compile:  cc -I. -I/home/offerit/offerit/vendor/maxmind-db/reader/ext -DPHP_ATOM_INC -I/home/offerit/offerit/vendor/maxmind-db/reader/ext/include -I/home/offerit/offerit/vendor/maxmind-db/reader/ext/main -I/home/offerit/offerit/vendor/maxmind-db/reader/ext -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c  -fPIC -DPIC -o .libs/maxminddb.o
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘zim_MaxMind_Db_Reader___construct’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:119:31: warning: implicit declaration of function ‘zend_object_store_get_object’; did you mean ‘zend_objects_store_destroy’? [-Wimplicit-function-declaration]
     maxminddb_obj *mmdb_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                               zend_objects_store_destroy
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:119:31: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘zim_MaxMind_Db_Reader_get’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:135:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         (maxminddb_obj *)zend_object_store_get_object(
         ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘zim_MaxMind_Db_Reader_metadata’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:206:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         (maxminddb_obj *)zend_object_store_get_object(
         ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:221:5: warning: implicit declaration of function ‘ALLOC_INIT_ZVAL’ [-Wimplicit-function-declaration]
     ALLOC_INIT_ZVAL(metadata_array);
     ^~~~~~~~~~~~~~~
In file included from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14:0,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:228:36: warning: passing argument 1 of ‘zend_call_method’ from incompatible pointer type [-Wincompatible-pointer-types]
     zend_call_method_with_1_params(&return_value, metadata_ce,
                                    ^
/usr/include/php/20170718/Zend/zend_interfaces.h:48:19: note: in definition of macro ‘zend_call_method_with_1_params’
  zend_call_method(obj, obj_ce, fn_proxy, function_name, sizeof(function_name)-1, retval, 1, arg1, NULL)
                   ^~~
In file included from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14:0,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_interfaces.h:42:16: note: expected ‘zval * {aka struct _zval_struct *}’ but argument is of type ‘zval ** {aka struct _zval_struct **}’
 ZEND_API zval* zend_call_method(zval *object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, size_t function_name_len, zval *retval, int param_count, zval* arg1, zval* arg2);
                ^~~~~~~~~~~~~~~~
In file included from /usr/include/php/20170718/Zend/zend.h:37:0,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:24,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_variables.h:87:48: warning: passing argument 1 of ‘_zval_ptr_dtor’ from incompatible pointer type [-Wincompatible-pointer-types]
 #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
                                                ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:233:5: note: in expansion of macro ‘zval_ptr_dtor’
     zval_ptr_dtor(&metadata_array);
     ^~~~~~~~~~~~~
/usr/include/php/20170718/Zend/zend_variables.h:79:15: note: expected ‘zval * {aka struct _zval_struct *}’ but argument is of type ‘zval ** {aka struct _zval_struct **}’
 ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC);
               ^~~~~~~~~~~~~~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘zim_MaxMind_Db_Reader_close’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:243:31: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     maxminddb_obj *mmdb_obj = (maxminddb_obj *)zend_object_store_get_object(
                               ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘handle_entry_data_list’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:270:23: error: macro "ZVAL_STRINGL" passed 4 arguments, but takes just 3
                      1);
                       ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:267:9: error: ‘ZVAL_STRINGL’ undeclared (first use in this function); did you mean ‘ZEND_STR_NULL’?
         ZVAL_STRINGL(z_value,
         ^~~~~~~~~~~~
         ZEND_STR_NULL
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:267:9: note: each undeclared identifier is reported only once for each function it appears in
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:274:62: error: macro "ZVAL_STRINGL" passed 4 arguments, but takes just 3
                      entry_data_list->entry_data.data_size, 1);
                                                              ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘handle_uint128’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:383:36: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
     ZVAL_STRING(z_value, num_str, 1);
                                    ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:383:5: error: ‘ZVAL_STRING’ undeclared (first use in this function); did you mean ‘ZEND_STR_LINE’?
     ZVAL_STRING(z_value, num_str, 1);
     ^~~~~~~~~~~
     ZEND_STR_LINE
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘handle_uint64’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:396:36: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
     ZVAL_STRING(z_value, int_str, 0);
                                    ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:396:5: error: ‘ZVAL_STRING’ undeclared (first use in this function); did you mean ‘ZEND_STR_LINE’?
     ZVAL_STRING(z_value, int_str, 0);
     ^~~~~~~~~~~
     ZEND_STR_LINE
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘lookup_class’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:403:27: warning: passing argument 1 of ‘zend_lookup_class’ from incompatible pointer type [-Wincompatible-pointer-types]
         zend_lookup_class(name, strlen(name),
                           ^~~~
In file included from /usr/include/php/20170718/Zend/zend_API.h:31:0,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_execute.h:45:28: note: expected ‘zend_string * {aka struct _zend_string *}’ but argument is of type ‘const char *’
 ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
                            ^~~~~~~~~~~~~~~~~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:403:9: error: too many arguments to function ‘zend_lookup_class’
         zend_lookup_class(name, strlen(name),
         ^~~~~~~~~~~~~~~~~
In file included from /usr/include/php/20170718/Zend/zend_API.h:31:0,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_execute.h:45:28: note: declared here
 ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
                            ^~~~~~~~~~~~~~~~~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:402:17: warning: comparison between pointer and integer
     if (FAILURE ==
                 ^~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: At top level:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:426:8: error: unknown type name ‘zend_object_value’
 static zend_object_value maxminddb_create_handler(
        ^~~~~~~~~~~~~~~~~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘maxminddb_create_handler’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:429:5: error: unknown type name ‘zend_object_value’; did you mean ‘zend_objects_store’?
     zend_object_value retval;
     ^~~~~~~~~~~~~~~~~
     zend_objects_store
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:440:11: error: request for member ‘handle’ in something not a structure or union
     retval.handle = zend_objects_store_put(obj, NULL,
           ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:440:44: warning: passing argument 1 of ‘zend_objects_store_put’ from incompatible pointer type [-Wincompatible-pointer-types]
     retval.handle = zend_objects_store_put(obj, NULL,
                                            ^~~
In file included from /usr/include/php/20170718/Zend/zend_globals.h:35:0,
                 from /usr/include/php/20170718/Zend/zend_compile.h:702,
                 from /usr/include/php/20170718/Zend/zend_modules.h:26,
                 from /usr/include/php/20170718/Zend/zend_API.h:27,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_objects_API.h:59:15: note: expected ‘zend_object * {aka struct _zend_object *}’ but argument is of type ‘maxminddb_obj * {aka struct _maxminddb_obj *}’
 ZEND_API void zend_objects_store_put(zend_object *object);
               ^~~~~~~~~~~~~~~~~~~~~~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:440:21: error: too many arguments to function ‘zend_objects_store_put’
     retval.handle = zend_objects_store_put(obj, NULL,
                     ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/php/20170718/Zend/zend_globals.h:35:0,
                 from /usr/include/php/20170718/Zend/zend_compile.h:702,
                 from /usr/include/php/20170718/Zend/zend_modules.h:26,
                 from /usr/include/php/20170718/Zend/zend_API.h:27,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_objects_API.h:59:15: note: declared here
 ZEND_API void zend_objects_store_put(zend_object *object);
               ^~~~~~~~~~~~~~~~~~~~~~
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:443:11: error: request for member ‘handlers’ in something not a structure or union
     retval.handlers = &maxminddb_obj_handlers;
           ^
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c: In function ‘zm_startup_maxminddb’:
/home/offerit/offerit/vendor/maxmind-db/reader/ext/maxminddb.c:464:33: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     maxminddb_ce->create_object = maxminddb_create_handler;
                                 ^
Makefile:194: recipe for target 'maxminddb.lo' failed
make: *** [maxminddb.lo] Error 1

PHP_MAXMINDDB_VERSION has not been updated

I have built the extension at tag version 1.0.0 and phpinfo() shows that it's loaded, but says it's version 0.2.0. In ext/php_maxminddb.h I can see #define PHP_MAXMINDDB_VERSION setting this. Shouldn't this have been updated, and keep being updated with future releases?

Error compilig maxminddb.so on xenial with php7.2

Hi,

I instaled al dependencies

apt-get install libmaxminddb0 libmaxminddb-dev

I prepare the cimposer.json and get the libs

root@apache-php7:~# composer.phar install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
  - Installing maxmind-db/reader (v0.3.3): Downloading (100%)
  - Installing symfony/event-dispatcher (v2.8.47): Downloading (100%)
  - Installing guzzle/guzzle (v3.9.3): Downloading (100%)
  - Installing geoip2/geoip2 (v0.6.3): Downloading (100%)

I did the phpize

root@apache-php7:~# cd vendor/maxmind-db/reader/ext
root@apache-php7:~/vendor/maxmind-db/reader/ext# phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718

I did the configure

root@apache-php7:~/vendor/maxmind-db/reader/ext# ./configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20170718
checking for PHP installed headers prefix... /usr/include/php/20170718
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking Whether to enable the MaxMind DB Reader extension... yes, shared
checking for MaxMind DB debug support... no
checking for MMDB_open in -lmaxminddb... yes
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands

And I tryed to do the make

root@apache-php7:~/vendor/maxmind-db/reader/ext# make
/bin/bash /root/vendor/maxmind-db/reader/ext/libtool --mode=compile cc  -I. -I/root/vendor/maxmind-db/reader/ext -DPHP_ATOM_INC -I/root/vendor/maxmind-db/reader/ext/include -I/root/vendor/maxmind-db/reader/ext/main -I/root/vendor/maxmind-db/reader/ext -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /root/vendor/maxmind-db/reader/ext/maxminddb.c -o maxminddb.lo
libtool: compile:  cc -I. -I/root/vendor/maxmind-db/reader/ext -DPHP_ATOM_INC -I/root/vendor/maxmind-db/reader/ext/include -I/root/vendor/maxmind-db/reader/ext/main -I/root/vendor/maxmind-db/reader/ext -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/vendor/maxmind-db/reader/ext/maxminddb.c  -fPIC -DPIC -o .libs/maxminddb.o
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'zim_MaxMind_Db_Reader___construct':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:119:31: warning: implicit declaration of function 'zend_object_store_get_object' [-Wimplicit-function-declaration]
     maxminddb_obj *mmdb_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                               ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:119:31: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'zim_MaxMind_Db_Reader_get':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:135:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         (maxminddb_obj *)zend_object_store_get_object(
         ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'zim_MaxMind_Db_Reader_metadata':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:206:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         (maxminddb_obj *)zend_object_store_get_object(
         ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:221:5: warning: implicit declaration of function 'ALLOC_INIT_ZVAL' [-Wimplicit-function-declaration]
     ALLOC_INIT_ZVAL(metadata_array);
     ^
In file included from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14:0,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/root/vendor/maxmind-db/reader/ext/maxminddb.c:228:36: warning: passing argument 1 of 'zend_call_method' from incompatible pointer type [-Wincompatible-pointer-types]
     zend_call_method_with_1_params(&return_value, metadata_ce,
                                    ^
/usr/include/php/20170718/Zend/zend_interfaces.h:48:19: note: in definition of macro 'zend_call_method_with_1_params'
  zend_call_method(obj, obj_ce, fn_proxy, function_name, sizeof(function_name)-1, retval, 1, arg1, NULL)
                   ^
In file included from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14:0,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_interfaces.h:42:16: note: expected 'zval * {aka struct _zval_struct *}' but argument is of type 'zval ** {aka struct _zval_struct **}'
 ZEND_API zval* zend_call_method(zval *object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, size_t function_name_len, zval *retval, int param_count, zval* arg1, zval* arg2);
                ^
In file included from /usr/include/php/20170718/Zend/zend.h:37:0,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:24,
                 from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_variables.h:87:48: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type [-Wincompatible-pointer-types]
 #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
                                                ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:233:5: note: in expansion of macro 'zval_ptr_dtor'
     zval_ptr_dtor(&metadata_array);
     ^
/usr/include/php/20170718/Zend/zend_variables.h:79:15: note: expected 'zval * {aka struct _zval_struct *}' but argument is of type 'zval ** {aka struct _zval_struct **}'
 ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC);
               ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'zim_MaxMind_Db_Reader_close':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:243:31: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     maxminddb_obj *mmdb_obj = (maxminddb_obj *)zend_object_store_get_object(
                               ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'handle_entry_data_list':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:270:23: error: macro "ZVAL_STRINGL" passed 4 arguments, but takes just 3
                      1);
                       ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:267:9: error: 'ZVAL_STRINGL' undeclared (first use in this function)
         ZVAL_STRINGL(z_value,
         ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:267:9: note: each undeclared identifier is reported only once for each function it appears in
/root/vendor/maxmind-db/reader/ext/maxminddb.c:274:62: error: macro "ZVAL_STRINGL" passed 4 arguments, but takes just 3
                      entry_data_list->entry_data.data_size, 1);
                                                              ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'handle_uint128':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:383:36: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
     ZVAL_STRING(z_value, num_str, 1);
                                    ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:383:5: error: 'ZVAL_STRING' undeclared (first use in this function)
     ZVAL_STRING(z_value, num_str, 1);
     ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'handle_uint64':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:396:36: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
     ZVAL_STRING(z_value, int_str, 0);
                                    ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:396:5: error: 'ZVAL_STRING' undeclared (first use in this function)
     ZVAL_STRING(z_value, int_str, 0);
     ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'lookup_class':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:403:27: warning: passing argument 1 of 'zend_lookup_class' from incompatible pointer type [-Wincompatible-pointer-types]
         zend_lookup_class(name, strlen(name),
                           ^
In file included from /usr/include/php/20170718/Zend/zend_API.h:31:0,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_execute.h:45:28: note: expected 'zend_string * {aka struct _zend_string *}' but argument is of type 'const char *'
 ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
                            ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:403:9: error: too many arguments to function 'zend_lookup_class'
         zend_lookup_class(name, strlen(name),
         ^
In file included from /usr/include/php/20170718/Zend/zend_API.h:31:0,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_execute.h:45:28: note: declared here
 ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
                            ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:402:17: warning: comparison between pointer and integer
     if (FAILURE ==
                 ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: At top level:
/root/vendor/maxmind-db/reader/ext/maxminddb.c:424:8: error: unknown type name 'zend_object_value'
 static zend_object_value maxminddb_create_handler(
        ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'maxminddb_create_handler':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:427:5: error: unknown type name 'zend_object_value'
     zend_object_value retval;
     ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:438:11: error: request for member 'handle' in something not a structure or union
     retval.handle = zend_objects_store_put(obj, NULL,
           ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:438:44: warning: passing argument 1 of 'zend_objects_store_put' from incompatible pointer type [-Wincompatible-pointer-types]
     retval.handle = zend_objects_store_put(obj, NULL,
                                            ^
In file included from /usr/include/php/20170718/Zend/zend_globals.h:35:0,
                 from /usr/include/php/20170718/Zend/zend_compile.h:702,
                 from /usr/include/php/20170718/Zend/zend_modules.h:26,
                 from /usr/include/php/20170718/Zend/zend_API.h:27,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_objects_API.h:59:15: note: expected 'zend_object * {aka struct _zend_object *}' but argument is of type 'maxminddb_obj * {aka struct _maxminddb_obj *}'
 ZEND_API void zend_objects_store_put(zend_object *object);
               ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:438:21: error: too many arguments to function 'zend_objects_store_put'
     retval.handle = zend_objects_store_put(obj, NULL,
                     ^
In file included from /usr/include/php/20170718/Zend/zend_globals.h:35:0,
                 from /usr/include/php/20170718/Zend/zend_compile.h:702,
                 from /usr/include/php/20170718/Zend/zend_modules.h:26,
                 from /usr/include/php/20170718/Zend/zend_API.h:27,
                 from /usr/include/php/20170718/Zend/zend_interfaces.h:25,
                 from /root/vendor/maxmind-db/reader/ext/php_maxminddb.h:14,
                 from /root/vendor/maxmind-db/reader/ext/maxminddb.c:14:
/usr/include/php/20170718/Zend/zend_objects_API.h:59:15: note: declared here
 ZEND_API void zend_objects_store_put(zend_object *object);
               ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c:441:11: error: request for member 'handlers' in something not a structure or union
     retval.handlers = &maxminddb_obj_handlers;
           ^
/root/vendor/maxmind-db/reader/ext/maxminddb.c: In function 'zm_startup_maxminddb':
/root/vendor/maxmind-db/reader/ext/maxminddb.c:462:33: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     maxminddb_ce->create_object = maxminddb_create_handler;
                                 ^
Makefile:194: recipe for target 'maxminddb.lo' failed
make: *** [maxminddb.lo] Error 1

Any idea? Thanks.

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.

PECL package

Should this be added to the PECL repository for easy download and access?

Merge into a single class, drop forced Composer

I see no reason to have 20KB of code (about 680 lines of code total) span multiple files. Using Reader requires loading ALL of the other files anyway. Toss the InvalidDatabaseException, since it does absolutely nothing new that Exception doesn't already do, and then merge the rest into a single class. Doing all of that will simplify this project.

I use HTML Purifier, which has a special "standalone" build. Basically looking for something similar here.

Don't force Composer on everyone. Not everyone can use nor will want to use Composer (for a wide variety of reasons).

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

Get ISP by it's AS number

For an administrative system we want to do a database lookup based on the as number in the ISP database. Currently, lookups can only be based on IP address. Is there any way in which this can be supported?

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.

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.