Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36624ae87a | ||
|
|
08697f2e7b | ||
|
|
2f9746c32b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
_site
|
_site
|
||||||
.gh-pages
|
.gh-pages
|
||||||
.idea
|
.idea
|
||||||
|
GeoLite2-City.mmdb
|
||||||
build
|
build
|
||||||
composer.lock
|
composer.lock
|
||||||
composer.phar
|
composer.phar
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.8.1 (2014-09-12)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* The check added to the `GeoIP2\Database\Reader` lookup methods in 0.8.0 did
|
||||||
|
not work with the GeoIP2 City Database Subset by Continent with World
|
||||||
|
Countries databases. This has been fixed. Fixes GitHub issue #23.
|
||||||
|
|
||||||
0.8.0 (2014-09-10)
|
0.8.0 (2014-09-10)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ You should now have the file `composer.phar` in your project directory.
|
|||||||
Run in your project root:
|
Run in your project root:
|
||||||
|
|
||||||
```
|
```
|
||||||
php composer.phar require geoip2/geoip2:~0.8.0
|
php composer.phar require geoip2/geoip2:~0.8.1
|
||||||
```
|
```
|
||||||
|
|
||||||
You should now have the files `composer.json` and `composer.lock` as well as
|
You should now have the files `composer.json` and `composer.lock` as well as
|
||||||
|
|||||||
26
bin/benchmark.php
Executable file
26
bin/benchmark.php
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../vendor/autoload.php';
|
||||||
|
|
||||||
|
use GeoIp2\Database\Reader;
|
||||||
|
use GeoIp2\Exception\AddressNotFoundException;
|
||||||
|
|
||||||
|
$reader = new Reader('GeoLite2-City.mmdb');
|
||||||
|
$count = 40000;
|
||||||
|
$startTime = microtime(true);
|
||||||
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
$ip = long2ip(rand(0, pow(2, 32) -1));
|
||||||
|
try {
|
||||||
|
$t = $reader->city($ip);
|
||||||
|
} catch (AddressNotFoundException $e) {
|
||||||
|
}
|
||||||
|
if ($i % 1000 == 0) {
|
||||||
|
print($i . ' ' . $ip . "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$endTime = microtime(true);
|
||||||
|
|
||||||
|
$duration = $endTime - $startTime;
|
||||||
|
print('Requests per second: ' . $count / $duration . "\n");
|
||||||
@@ -71,11 +71,7 @@ class Reader implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function city($ipAddress)
|
public function city($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->modelFor(
|
return $this->modelFor('City', 'City', $ipAddress);
|
||||||
'City',
|
|
||||||
array('GeoLite2-City', 'GeoIP2-City'),
|
|
||||||
$ipAddress
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,11 +88,7 @@ class Reader implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function country($ipAddress)
|
public function country($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->modelFor(
|
return $this->modelFor('Country', 'Country', $ipAddress);
|
||||||
'Country',
|
|
||||||
array('GeoLite2-Country', 'GeoIP2-Country'),
|
|
||||||
$ipAddress
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connectionType($ipAddress)
|
public function connectionType($ipAddress)
|
||||||
@@ -126,16 +118,9 @@ class Reader implements ProviderInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function modelFor($class, $types, $ipAddress)
|
private function modelFor($class, $type, $ipAddress)
|
||||||
{
|
{
|
||||||
if (!in_array($this->metadata()->databaseType, $types)) {
|
$record = $this->getRecord($class, $type, $ipAddress);
|
||||||
$method = lcfirst($class);
|
|
||||||
throw new \BadMethodCallException(
|
|
||||||
"The $method method cannot be used to open a "
|
|
||||||
. $this->metadata()->databaseType . " database"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$record = $this->getRecord($ipAddress);
|
|
||||||
|
|
||||||
$record['traits']['ip_address'] = $ipAddress;
|
$record['traits']['ip_address'] = $ipAddress;
|
||||||
$class = "GeoIp2\\Model\\" . $class;
|
$class = "GeoIp2\\Model\\" . $class;
|
||||||
@@ -145,15 +130,7 @@ class Reader implements ProviderInterface
|
|||||||
|
|
||||||
private function flatModelFor($class, $type, $ipAddress)
|
private function flatModelFor($class, $type, $ipAddress)
|
||||||
{
|
{
|
||||||
if ($this->metadata()->databaseType !== $type) {
|
$record = $this->getRecord($class, $type, $ipAddress);
|
||||||
$method = lcfirst($class);
|
|
||||||
throw new \BadMethodCallException(
|
|
||||||
"The $method method cannot be used to open a "
|
|
||||||
. $this->metadata()->databaseType . " database"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$record = $this->getRecord($ipAddress);
|
|
||||||
|
|
||||||
$record['ip_address'] = $ipAddress;
|
$record['ip_address'] = $ipAddress;
|
||||||
$class = "GeoIp2\\Model\\" . $class;
|
$class = "GeoIp2\\Model\\" . $class;
|
||||||
@@ -161,8 +138,15 @@ class Reader implements ProviderInterface
|
|||||||
return new $class($record);
|
return new $class($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRecord($ipAddress)
|
private function getRecord($class, $type, $ipAddress)
|
||||||
{
|
{
|
||||||
|
if (strpos($this->metadata()->databaseType, $type) === false) {
|
||||||
|
$method = lcfirst($class);
|
||||||
|
throw new \BadMethodCallException(
|
||||||
|
"The $method method cannot be used to open a "
|
||||||
|
. $this->metadata()->databaseType . " database"
|
||||||
|
);
|
||||||
|
}
|
||||||
$record = $this->dbReader->get($ipAddress);
|
$record = $this->dbReader->get($ipAddress);
|
||||||
if ($record === null) {
|
if ($record === null) {
|
||||||
throw new AddressNotFoundException(
|
throw new AddressNotFoundException(
|
||||||
|
|||||||
Reference in New Issue
Block a user