PHPackages                             xieyuhua/xyhip2region - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xieyuhua/xyhip2region

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xieyuhua/xyhip2region
=====================

Ip2Region for PHP

v1.0.2(1y ago)04Apache-2.0PHPPHP &gt;=5.6

Since Jul 2Pushed 1y agoCompare

[ Source](https://github.com/xieyuhua/xyhip2region)[ Packagist](https://packagist.org/packages/xieyuhua/xyhip2region)[ Docs](https://github.com/xieyuhua/xyhip2region)[ RSS](/packages/xieyuhua-xyhip2region/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/26f597857d6aff2815ddb28ef8920d0d33aa282726fa9aab324bfb3bbe132b21/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f697032726567696f6e2f762f737461626c65)](https://packagist.org/packages/zoujingli/ip2region)[![Total Downloads](https://camo.githubusercontent.com/fea5425209aec0e2b48e106321adfd87d5e439382fe50beae8b657c0560dfa66/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f697032726567696f6e2f646f776e6c6f616473)](https://packagist.org/packages/zoujingli/ip2region)[![Latest Unstable Version](https://camo.githubusercontent.com/1409367e22a62c6a6bd5522682e281a5ac3f5a34c7ff00ebb1f1d977ad945f56/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f697032726567696f6e2f762f756e737461626c65)](https://packagist.org/packages/zoujingli/ip2region)[![License](https://camo.githubusercontent.com/ee87b0a81848a3a55eab7bbf50e91082e0771e55c7f22606be589d7ed1f0e03a/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f697032726567696f6e2f6c6963656e7365)](https://packagist.org/packages/zoujingli/ip2region)

本库基于 [ip2region](https://github.com/lionsoul2014/ip2region) ，简单整合方便使用`Composer`来管理。

Ip2region 是什么？
--------------

[](#ip2region-是什么)

[ip2region](https://github.com/lionsoul2014/ip2region) - 准确率 99.9% 的离线IP地址定位库，0.0x 毫秒级查询，ip2region.db 数据库只有数MB，提供了查询绑定和 Binary, B 树，内存三种查询算法。

Ip2region 特性
------------

[](#ip2region-特性)

### 99.9%准确率

[](#999准确率)

数据聚合了一些知名ip到地名查询提供商的数据，这些是他们官方的的准确率，经测试着实比经典的纯真IP定位准确一些。
ip2region的数据聚合自以下服务商的开放API或者数据(升级程序每秒请求次数2到4次):
01, &gt;80%, 淘宝IP地址库,
02, ≈10%, GeoIP,
03, ≈2%, 纯真IP库,
**备注：**如果上述开放API或者数据都不给开放数据时ip2region将停止数据的更新服务。

### 标准化的数据格式

[](#标准化的数据格式)

每条ip数据段都固定了格式：

```
_城市Id|国家|区域|省份|城市|ISP_

```

只有中国的数据精确到了城市，其他国家有部分数据只能定位到国家，后前的选项全部是0，已经包含了全部你能查到的大大小小的国家（请忽略前面的城市Id，个人项目需求）。

### 体积小

[](#体积小)

包含了全部的 IP，生成的数据库文件 ip2region.db 只有几MB，最小的版本只有 1.5MB，随着数据的详细度增加数据库的大小也慢慢增大，目前还没超过8MB。

### 查询速度快

[](#查询速度快)

全部的查询客户端单次查询都在 0.x 毫秒级别，内置了三种查询算法

1. memory 算法：整个数据库全部载入内存，单次查询都在 0.1x 毫秒内，C语言的客户端单次查询在 0.00x 毫秒级别。
2. binary 算法：基于二分查找，基于 ip2region.db 文件，不需要载入内存，单次查询在 0.x 毫秒级别。
3. b-tree 算法：基于 btree 算法，基于 ip2region.db 文件，不需要载入内存，单词查询在 0.x 毫秒级别，比 binary 算法更快。

任何客户端 b-tree 都比 binary 算法快，当然 memory 算法固然是最快的！

### Composer 安装

[](#composer-安装)

```
composer require xieyuhua/xyhip2region

```

### ip2region 使用

[](#ip2region-使用)

```
$ip2region = new Ip2Region();

$ip = '101.105.35.57';

$info = $ip2region->btreeSearch($ip);

var_export($info, true);

// array (
//     'city_id' => 2163,
//     'region' => '中国|华南|广东省|深圳市|鹏博士',
// )
```

###  Health Score

23

—

LowBetter than 25% of packages

Maintenance46

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

411d ago

PHP version history (2 changes)v1.0.1PHP &gt;=7.3

v1.0.2PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6d13208e50f40d4cc45e5a821076d9af7e0001f1b7fa42d3cfac7edafabf4bb?d=identicon)[xieyuhua](/maintainers/xieyuhua)

---

Tags

Ip2Region

### Embed Badge

![Health badge](/badges/xieyuhua-xyhip2region/health.svg)

```
[![Health](https://phpackages.com/badges/xieyuhua-xyhip2region/health.svg)](https://phpackages.com/packages/xieyuhua-xyhip2region)
```

###  Alternatives

[zoujingli/ip2region

PHP IP 地理位置查询库，基于 ip2region XDB，支持 IPv4/IPv6、内置 IPv4 数据库、IPv6 按需下载和多种缓存策略

1.4k491.4k71](/packages/zoujingli-ip2region)[js-phpize/js-phpize

Convert js-like syntax to standalone PHP code.

23417.5k3](/packages/js-phpize-js-phpize)[paulzi/yii2-sortable

Sortable Behavior for Yii2

15329.3k4](/packages/paulzi-yii2-sortable)[firstphp/ip2region

ip2region for hyperf

128.8k](/packages/firstphp-ip2region)[b13/doktypemapper

Maps your page.doktype to page.backend\_layout

14136.7k](/packages/b13-doktypemapper)[youthage/laravel-geohash

LBS地理位置距离计算方法geohash，将一个经纬度信息，转换成一个可以排序，可以比较的字符串编码，用于高效搜索

1822.1k](/packages/youthage-laravel-geohash)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
