php的高性能精准IP查找类

采用了ip2region的PHP扩展模式


git clone https://github.com/lionsoul2014/ip2region.git 

cd ip2region 

cp binding/php_extension/php7/ip2region 到 php source code 的ext目录下 
cp -r binding/php_extension/php7/ip2region  /usr/local/php71/include/php/ext/

cp -r binding/php_extension/php7/ip2region  /usr/local/php71/include/php/ext/
cp -r binding/php_extension/php5/ip2region  /usr/local/php56/include/php/ext/ 


----------


cp binding/c/下面所有的文件到 php source code 的ext/ip2region/lib 目录下 
cp -r binding/c/   /usr/local/php71/include/php/ext/ip2region/lib/
cp -r binding/c/   /usr/local/php56/include/php/ext/ip2region/lib/

c目录下面的文件移动

* 在ext/ip2region下,运行 

        phpize
        ./configure
        make && sudo make install


/usr/local/php71/lib/php/extensions/no-debug-non-zts-20160303/
extension=ip2region.so
ip2region.db_file=/usr/local/php71/lib/php/extensions/no-debug-non-zts-20160303/ip2region.db

相关代码

/**
 * ip2region - 最自由的ip地址查询库,ip到地区的映射库,提供Binary,B树和纯内存三种查询算法,妈妈再也不用担心我的ip地址定位。
 */
function look_ip2region($ip){
  return Ip2region:: btreeSearch(ip2long($ip));
}

你可能感兴趣的:(php扩展开发)