Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
maxmind-db-reader example script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 523

PostPosted: Fri Jan 11, 2019 10:05 am    Post subject: maxmind-db-reader example script Reply with quote

Hi,

After emerging maxmind-db-reader I tried the following PHP script:

index.php:
Code:
<?php
require 'MaxMind/Db/autoload.php';
use MaxMind\Db\Reader;
[...]
$reader = new Reader('/usr/share/GeoIP/GeoLite2-City.mmdb'); // line 31


However, I'm getting errors in the log.
/var/log/apache2/ssl_error_log:
Code:

PHP Fatal error:  Uncaught Error: Class 'MaxMind\\Db\\Reader' not found in [..]index.php:31\
nStack trace:\n#0 {main}\n  thrown in [...]index.php on line 31


# emerge --info shows:
Code:
dev-php/maxmind-db-reader-1.3.0::gentoo was built with the following:
USE="-extension -test" ABI_X86="(64)" PHP_TARGETS="php5-6 php7-0 php7-1 php7-2"

dev-lang/php-7.0.19::gentoo was built with the following:
USE="acl apache2 berkdb bzip2 calendar cli crypt ctype curl embed fileinfo filter ftp gd gdbm hash iconv ipv6 json kerberos ldap mssql mysql mysqli nls odbc opcache phar posix postgres readline session simplexml soap sockets ssl tokenizer unicode xml xmlreader xmlrpc xmlwriter zip zlib -bcmath -cdb -cgi -cjk -coverage -debug -enchant -exif (-firebird) -flatfile -fpm -gmp -imap -inifile -intl -iodbc -ldap-sasl -libedit -libressl -mhash -oci8-instant-client -pcntl -pdo -phpdbg -qdbm -recode (-selinux) -sharedmem -snmp -spell -sqlite -systemd -sysvipc -threads -tidy -truetype -wddx -webp -xpm -xslt" ABI_X86="(64)"


Any ideas?
Back to top
View user's profile Send private message
guitou
Guru
Guru


Joined: 02 Oct 2003
Posts: 389
Location: France

PostPosted: Fri Jan 11, 2019 12:32 pm    Post subject: Reply with quote

Hello.

Been a while since I did not play really with PHP, but looking at your problem, I suppose PHP autoloading just does not come out of the box, while the example you took assumes your code uses some.
Provided my guess is right, then you may try and require MaxMind/Db/Reader.php instead, or implement an Autoloader class.

Hope this helps.

++
Gi)
Back to top
View user's profile Send private message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 523

PostPosted: Fri Jan 11, 2019 1:38 pm    Post subject: Reply with quote

Thanks. I'm just starting to use this library, and the ebuild states the following:

Code:
pkg_postinst(){
        elog "${PN} has been installed in /usr/share/php/MaxMind/Db/."
        elog "To use it in a script, require('MaxMind/Db/autoload.php'),"
        elog "and then most of the examples in the documentation should"
        elog "work without further modification."
}


Obviously, it's incorrect or incomplete.

I changed my first 2 lines to:

Code:
require 'MaxMind/Db/Reader.php';
require 'MaxMind/Db/Reader/Decoder.php';
require 'MaxMind/Db/Reader/InvalidDatabaseException.php';
require 'MaxMind/Db/Reader/Metadata.php';
require 'MaxMind/Db/Reader/Util.php';
use MaxMind\Db\Reader;


and it seems to work fine now.
I guess the ebuild needs a small info fix, or an extra PHP system check.

Thanks again.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum