README
PROLOGUE
My project demands on detecting and storing accessed IP data.
So I found geoip/geoip package. And everything else is to store it.
The best way is serialize or create record in DB. The second way with Doctrine 2 is very slow as appeared in my experience., (*1)
Why not geoip2/geoip2 or MaxMind-DB-Reader-php with .mmdb
Really? It contains wished class Record for serialization already but:
As experiment showed:, (*2)
- Record Object has all Country name translations what I do with internalization library.
- Record Object is too huge so Its serialization take too long string.
-
It much SLOWLY then geoip1 with sqlite db. In 2-3 times. (Tested on about 2500 IPs)
So I decided to create alternate Record object that will utilize fast geoip sqlite db and fit to
now-day Object using. It easily can be extended to Doctrine Entity or Document., (*3)
How to install
Install it by composer., (*4)
{
"require": {
"vnagara/geoip-module": "1.*"
}
}
Download geoip sql DB to data/GeoLiteCity.dat or set another path in configuration file.
On linux with wget you can use this command (inside project root):, (*5)
wget -O - http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | gzip -dc > data/GeoLiteCity.dat
In application.config.php enable GeoipModule module., (*6)
New methods:
- In view helpers: geoipRecord($ipAddress) will return GeoipRecord.
- There is new service geoip. So in controller it is accessible by:
/** @var \GeoipModule\Service\Geoip */
$geoip = $this->getServiceLocator()->get('geoip');
/** @var \GeoipModule\Object\Record */
$recordOfSomeIpAddress = $geoip->find('184.154.227.14');
$city = $recordOfSomeIpAddress->getCity(); // Chicago
// The same:
$recordOfSomeIpAddress = $geoip->lookup('184.154.227.14');
// To use ip from $_SERVER['REMOTE_ADDR']
$record = $geoip->find();
Doctrine ORM
Template of Entity with annotation lays by path: src/GeoipModule/Entity/Record.php, (*7)