Giter Site home page Giter Site logo

ip2region-sdk-php's Introduction

ip2region SDK for PHP (定期更新数据版)

Author Software License Latest Version Total Downloads php 7.1+

Installation

运行环境要求 PHP 7.1 及以上版本,以及cURL

定期更新数据版

特点:xdb数据封装在composer包内,数据会定期更新

composer require chinayin/ip2region

官方原生查询包

特点:包更小,数据路径自定义

使用方法:github.com/chinayin/ip2region-core

Quick Examples

完全基于文件的查询

use ip2region\Ip2Region;

$ip = '1.2.3.4';
try {
    $searcher = Ip2Region::newWithFileOnly();
    $region = $searcher->search($ip);
    // 或
    $region = Ip2Region::search($ip);
    var_dump($region);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}

备注:并发使用,每个线程或者协程需要创建一个独立的 searcher 对象。

缓存 VectorIndex 索引

如果你的 php 母环境支持,可以预先加载 vectorIndex 缓存,然后做成全局变量,每次创建 Searcher 的时候使用全局的 vectorIndex,可以减少一次固定的 IO 操作从而加速查询,减少 io 压力。

use ip2region\Ip2Region;

$ip = '1.2.3.4';
try {
    $region = Ip2Region::newWithVectorIndex()->search($ip);
    var_dump($region);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}

备注:并发使用,每个线程或者协程需要创建一个独立的 searcher 对象,但是都共享统一的只读 vectorIndex。

缓存整个 xdb 数据

如果你的 PHP 母环境支持,可以预先加载整个 xdb 的数据到内存,这样可以实现完全基于内存的查询,类似之前的 memory search 查询。

use ip2region\Ip2Region;

$ip = '1.2.3.4';
try {
    $region = Ip2Region::newWithBuffer()->search($ip);
    var_dump($region);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}

备注:并发使用,用整个 xdb 缓存创建的 searcher 对象可以安全用于并发。

ip2region-sdk-php's People

Contributors

chinayin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.