PHPackages                             larvaplus/laravel-ip2region - 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. larvaplus/laravel-ip2region

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

larvaplus/laravel-ip2region
===========================

This is a ip2region.

1111(1y ago)08MITPHPPHP ^8.0

Since Dec 3Pushed 1y agoCompare

[ Source](https://github.com/wuxuejian/laravel-ip2region)[ Packagist](https://packagist.org/packages/larvaplus/laravel-ip2region)[ RSS](/packages/larvaplus-laravel-ip2region/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

laravel-ip2region
=================

[](#laravel-ip2region)

Laravel 的 ip2region 位置查询模块

[![Latest Stable Version](https://camo.githubusercontent.com/266c331146aa8233b272c3fde62b767d528b00e3efde56652a400a362e1ecb5d/68747470733a2f2f706f7365722e707567782e6f72672f6c617276612f6c61726176656c2d697032726567696f6e2f762f737461626c652e737667)](https://packagist.org/packages/larva/laravel-ip2region)[![Latest Unstable Version](https://camo.githubusercontent.com/63335ae9a1f9709af1dd6e0521773653f461d7ce667b92d9943eac07514adf1e/68747470733a2f2f706f7365722e707567782e6f72672f6c617276612f6c61726176656c2d697032726567696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/larva/laravel-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 算法固然是最快的！

环境需求
----

[](#环境需求)

- PHP &gt;= 7.4

安装
--

[](#安装)

```
composer require larva/laravel-ip2region
```

```
$info=  \Larva\Ip2Region\Ip2Region::find('218.1.2.3');
var_export($info, true);

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

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

525d ago

### Community

Maintainers

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

---

Top Contributors

[![xutongle](https://avatars.githubusercontent.com/u/46956076?v=4)](https://github.com/xutongle "xutongle (4 commits)")[![wuxuejian](https://avatars.githubusercontent.com/u/4558715?v=4)](https://github.com/wuxuejian "wuxuejian (3 commits)")

---

Tags

laravelgeoipip2locationIp2Region

### Embed Badge

![Health badge](/badges/larvaplus-laravel-ip2region/health.svg)

```
[![Health](https://phpackages.com/badges/larvaplus-laravel-ip2region/health.svg)](https://phpackages.com/packages/larvaplus-laravel-ip2region)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[torann/geoip

Support for multiple Geographical Location services.

2.2k14.2M76](/packages/torann-geoip)[adrianorosa/laravel-geolocation

Laravel Geo Location package to get details for a given IP Address

6593.3k1](/packages/adrianorosa-laravel-geolocation)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[eseath/sypexgeo

A PHP package for working with the SypexGeo database file.

13176.3k](/packages/eseath-sypexgeo)

PHPackages © 2026

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