gpslab / geoip2 Goto Github PK
View Code? Open in Web Editor NEWA Symfony Bundle for the Maxmind GeoIP2 API
Home Page: https://www.maxmind.com/
License: MIT License
A Symfony Bundle for the Maxmind GeoIP2 API
Home Page: https://www.maxmind.com/
License: MIT License
Hello,
How can i use ASN database with your bundle ?
Best regards
i ma using symofny 4
and try to download database with bin/console geoip2:update
but getting There are no commands defined in the "geoip2" namespace.
Hello,
Is it possible to add auto-wiring for the bundle ?
Thanks :)
Hi!
I need to inject the service into the controller method like this:
namespace App\Controller;
use GeoIp2\Database\Reader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ApiController extends AbstractController
{
public function someAction(Reader $reader)
{
dd($reader);
}
}
but i'm have this error:
"Cannot autowire argument $reader of \"App\\Controller\\ApiController::someAction()\": it references class \"GeoIp2\\Database\\Reader\" but no such service exists. You should maybe alias this class to the existing \"geoip2.reader\" service."
is it possible to do it somehow?
thanx
Hi there,
I've followed the steps to integrate the librairy in my project.
I've created a Service to use it in my code like so:
// src/Service/GeoipLib.php
namespace App\Services;
use GeoIp2\Database\Reader;
class GeoIPLib
{
private $reader;
public function __construct(Reader $reader)
{
$this->reader = $reader;
}
public function getCity($ip)
{
// get a GeoIP2 City model
$record = $this->reader->city($ip);
return $record->mostSpecificSubdivision->name;
}
public function getCountry($ip)
{
// get a GeoIP2 City model
$record = $this->reader->city($ip);
return $record->country->isoCode;
}
public function getPostalCode($ip)
{
// get a GeoIP2 City model
$record = $this->reader->city($ip);
return $record->postal->code;
}
}
and my config file is as follow:
# Read the README file for more detailed configuration information
# https://github.com/gpslab/geoip2
gpslab_geoip:
# You should specify your personal licence key
license: 'XXXXX'
# Edition ID of database you need
edition: 'GeoLite2-City'
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=XXXXX&suffix=tar.gz'
If I follow the url, it does download the file so the key seems good to me.
However, when I'm trying to use the librairy, I'm getting the following error message:
The file var/cache/dev/GeoLite2-City.mmdb does not exist or is not readable
Indeed, it does not exist in the cache folder.
Please help.
Thank you.
Some options in Travis CI config is outdated
root
: deprecated keysudo
(The keysudo
has no effect anymore.)
root
: missingos
, using the defaultlinux
root
: keymatrix
is an alias forjobs
, usingjobs
Hello,
Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\RuntimeException: "Cannot autowire argument $readerFactory of "App\Controller\Test\TestController::geoip()": it references class "GpsLab\Bundle\GeoIP2Bundle\Reader\ReaderFactory" but no such service exists." at C:\Projects\testProject\vendor\symfony\dependency-injection\Container.php line 435
Hide context Hide trace
[▼
"exception" => Symfony\Component\DependencyInjection\Exception\RuntimeException {#10076 ▶}
]
{▼
C:\Projects\testProject\vendor\symfony\dependency-injection\Container.php:435 {▼
Symfony\Component\DependencyInjection\Container->getService($registry, string $id, ?string $method, $load) …
› if (\is_string($load)) {
› throw new RuntimeException($load);
› }
}
...
Thanks
Rico
We declare as support Symfony 2.3 - 2.6, but this versions not support Symfony\Component\Console\Style\SymfonyStyle
what we use.
Symfony 2.3 - 2.6 not support Symfony\Component\Console\Style\SymfonyStyle
, so we should break this thary old versions.
This is required for flex symfony/recipes-contrib#837.
Maxmind changed their policy and user agreements about using their data so old urls like
https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
are not working anymore.
Any suggestions to move to other alternative or are you planning to fix this?
Hi there,
After I have followed the steps and added this bundle to my project, everything was working fine. But when I tried to update the database with the command ("php bin/console geoip2:update")
I have received an error. Do you have any idea what could make this issue.
In Filesystem.php line 179:
Failed to remove file "C:\Users\user\AppData\Local\Temp/603784fb9d6e84.54757459_GeoLite2.tar": unlink(C:\Users\user\AppData\Local\Temp/603784fb9d6e84.54757459_GeoL
ite2.tar): Resource temporarily unavailable
Thank You!
Since July 22nd, geoip2:update runs out of memory when updating the GeoLite2-City edition because the current memory usage exceeds the default 128MB memory limit on Fedora:Memory Usage: 21795872 Memory Peak Usage: 146951168
Two solutions:
ini_set('memory_limit', '256M');
before opening the archive with PharData
. Not a great solution in my opinion.Memory Usage: 17999088 Memory Peak Usage: 18098424
by replacinggeoip2/src/Downloader/MaxMindDownloader.php
Lines 74 to 85 in 5710d12
with:
use splitbrain\PHPArchive\Tar;
...
// extract tar.gz archive
$tar = new Tar();
$tar->open($tmp_zip);
$tar->extract($tmp_untar);
$tar->close();
unset($tar);
$this->logger->debug(sprintf('Tar archive extracted to %s', $tmp_untar));
Hi, thanks for the library!
I`m having quite some trouble understanding what the heck is going on. Basically, I want a service that I can use in Controllers and EventListeners.
After checking the issues here and comments, you mentioned to declare:
GeoIp2\Database\Reader:
alias: 'geoip2.reader'
public: true
However, this is not needed apparently. The moment you pass use GeoIp2\Database\Reader into the constructor, the following gets injected:
[ContainerLx2Tlzg\Reader_5400306 - GeoIp2\Database\Reader@proxy](http://.../_profiler/open?file=var\cache\dev\ContainerLx2Tlzg\Reader_5400306.php&line=7#line7) {#643 ▼
-valueHolder16a63: null
-initializer876c2: [Closure(&$wrappedInstance, LazyLoadingInterface $proxy)](http://.../_profiler/open?file=var\cache\dev\ContainerLx2Tlzg\**getGeoip2_Database_CityReaderService**.php&line=22#line22) {#647 ▼
class: "[ContainerLx2Tlzg\getGeoip2_Database_CityReaderService](http://.../_profiler/open?file=var\cache\dev\ContainerLx2Tlzg\getGeoip2_Database_CityReaderService.php&line=11#line11)"
use: {▼
$container: ContainerLx2Tlzg\App_KernelDevDebugContainer {#55 …}
}
}
As above the City reader gets injected automatically, and I have no way of getting the ASN reader for example. I have also commented out default_database but without any effect.
So back to my question, how to use your library properly and as intended?
The requirement is quite simple:
Many thanks!
It would be useful to be able to configure the permissions set on the downloaded databases instead of it being set to 0755. Also, it seems like 0644 would be permissive enough.
geoip2/src/Downloader/MaxMindDownloader.php
Line 124 in 767829c
Thanks to this PR #56 you can't choose a paid edition
So please add the following possible values:
PS: Work around for now:
default_database: 'default'
databases:
default:
edition: 'GeoLite2-City'
license: '<fill your license>'
# Paid version:
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoIP2-City&suffix=tar.gz&license_key=<fill your license>'```
3.4.47 Symfony version
Update will throw an UnexpectedValueException In MaxMindDownloader.php line 88:
Cannot decompress zip-based archives with whole-archive compression
Config:
gpslab_geoip:
license: 'xxx'
locales: [ 'en' ]
default_database: 'city'
databases:
asn:
edition: 'GeoLite2-ASN'
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=xxx&suffix=zip'
path: '%kernel.project_dir%/var/GeoLite2-ASN.mmdb'
city:
edition: 'GeoLite2-City'
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&license_key=xxx&suffix=zip'
path: '%kernel.project_dir%/var/GeoLite2-City.mmdb'
country:
edition: 'GeoLite2-Country'
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=xxx&suffix=zip'
path: '%kernel.project_dir%/var/GeoLite2-Country.mmdb'
Command:
php bin/console geoip2:update asn -vvv
zlib:
ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.11
Linked Version => 1.2.11
Phar:
Phar: PHP Archive support => enabled
Phar API version => 1.1.1
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => disabled (install ext/bz2)
Native OpenSSL support => enabled
Line | src/Downloader/MaxMindDownloader.php |
---|---|
82 | Call to an undefined method object::extractTo() . |
$zip = new \PharData($tmp_zip);
$tar = $zip->decompress();
$tar->extractTo($tmp_untar);
This is a false error because \Phar::decompress()
return a \Phar
.
Error in PHPStan phpstan/phpstan-src#114. Waiting for release this fix.
I've just started to configure your package, and it seems you cannot configure the path as per the documentation:
In ArrayNode.php line 314:
Unrecognized option "path" under "gpslab_geoip". Available options are "databases", "default_database", "license", "locales".
Please update the documentation to inform people where to put the path key:
gpslab_geoip:
path: '%kernel.project_dir%/var/GeoLite2-City.mmdb'
To:
databases:
city:
edition: 'GeoLite2-City'
path: '%kernel.project_dir%/var/GeoLite2-City.mmdb'
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.