github lionsoul2014/ip2region v3.2.0-release

9 hours ago
  1. PHP binding 提供了对 IPv6 的查询支持,具体使用文档请参考 PHP Binding,测试方式如下:
➜  php git:(master) php search_test.php --db=../../data/ip2region_v6.xdb
ip2region xdb searcher test program
source xdb file: ../../data/ip2region_v6.xdb (IPv6, vectorIndex)
type 'quit' to exit
ip2region>> ::
{region: |||, ioCount: 2, took: 0.03223 ms}
ip2region>> 2001:3:ffff:ffff:ffff:ffff:ffff:ffff
{region: 美国|加利福尼亚州|洛杉矶|专线用户, ioCount: 21, took: 0.06592 ms}
ip2region>> 240e:3b7:3272:d8d0:3b7b:3ee0:1d39:848
{region: 中国|广东省|深圳市|家庭宽带, ioCount: 14, took: 0.05078 ms}
  1. php binding 实现引入了命名空间 \ip2region\xdb 来进行管理,将具体的实现封装到了四个核心类,具体如下:
类名 描述
Util 全部的工具类函数都封装在这个类中,例如:parseIP / loadHeader / loadVectorIndex 等等。
IPv4 / IPv6 IP版本管理类,拆异化的 IPv4/IPv6 管理。
Searcher xdb 查询的具体实现封装,主要提供了 search(string) 和 searchByBytes(bytes) 两个查询接口。
  1. PHP 使用引入方式如下:
// 引入 xdb 类包,require 或者 autoload 对应的 class.
require 'xdb/Searcher.class.php'; 

// use 申明
use \ip2region\xdb\Util;
use \ip2region\xdb\{IPv4, IPv6};
use \ip2region\xdb\Searcher;

// 类的使用请参考 php binding 的 ReadMe
  1. 查询平均耗时:Razer 笔记本 / Ubuntu (电源均衡模式) + SATA SSD / VectorIndex 缓存,bench 结果如下:
➜  php git:(master) php bench_test.php --db=../../data/ip2region_v6.xdb --src=../../data/ipv6_source.txt
Bench finished, {cachePolicy: vectorIndex, total: 34159862, took: 1587s, cost: 0.046 ms/op}

341.6万个 IPv6 平均查询耗时为 46 微秒/次。

Don't miss a new ip2region release

NewReleases is sending notifications on new releases.