定制 martialbe/laravel-ip2region 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

martialbe/laravel-ip2region

最新稳定版本:v1.0.1

Composer 安装命令:

composer require martialbe/laravel-ip2region

包简介

ip2region 的Laravel扩展包

README 文档

README

ip2region 的Laravel扩展包。

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

要求

  • PHP >= 7.4
  • Laravel >=5.8

安装

composer require martialbe/laravel-ip2region

开始使用

  1. 创建配置文件
php artisan vendor:publish --provider="Martialbe\LaravelIp2region\ServiceProvider"
  1. 添加别名
'aliases' => [
    // ...
    "Ip2Region" => Martialbe\LaravelIp2region\Facade::class,
],
  1. 使用
    // array:5 [
    //     "country" => "中国"
    //     "area" => ""
    //     "state" => "上海"
    //     "city" => "上海市"
    //     "isp" => "电信"
    // ]
    \Ip2Region::ip("218.1.2.3")->toArray();


    // OR
    // 中国|0|上海|上海市|电信
    \Ip2Region::ip("218.1.2.3")->toString();

    // OR
    $region = \Ip2Region::ip("218.1.2.3");
    $region->country;
    $region->area;
    $region->state;
    $region->city;
    $region->isp;
  1. 更新数据库
    php artisan ip2region:update

其他使用方法

详情查看ip2region for php文档

缓存 VectorIndex 索引

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

// 1、从 dbPath 加载 VectorIndex 缓存,把下述的 vIndex 变量缓存到内存里面。
$vIndex = \Ip2Region::loadVectorIndexFromFile();

// 2、使用全局的 vIndex 创建带 VectorIndex 缓存的查询对象。
try {
    $searcher = \Ip2Region::setIndex($vIndex);
} catch (Exception $e) {
    printf("failed to create vectorIndex cached searcher with %s\n", $e);
    return;
}

// 3、查询
$region = $searcher->ip('1.2.3.4');
// 备注:并发使用,每个线程或者协程需要创建一个独立的 searcher 对象,但是都共享统一的只读 vectorIndex。

缓存整个 xdb 数据

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

// 1、从 dbPath 加载整个 xdb 到内存。
$cBuff = \Ip2Region::loadContentFromFile();

// 2、使用全局的 cBuff 创建带完全基于内存的查询对象。
try {
    $searcher = \Ip2Region::setDbcache($cBuff);
} catch (Exception $e) {
    printf("failed to create buffer cached searcher: %s\n", $e);
    return;
}

// 3、查询
$region = $searcher->ip('1.2.3.4');
// 备注:并发使用,用整个 xdb 缓存创建的 searcher 对象可以安全用于并发。

License

MIT

统计信息

  • 总下载量: 88
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固