pier-infor/geoliteip
Composer 安装命令:
composer require pier-infor/geoliteip
包简介
Pier-Infor Geoliteip.
README 文档
README
Geoliteip is a php tool to use and manage maxmind GeoLite2 free databases in mmdb format.
🌊 Features
- Use 3 free dbs as asn, country, city.
- Change db on the fly without re-instanciate.
- Input ip list from plain text file.
- Output as array, json, csv.
- Update dbs on the fly or from composer.
👍 Pro
- Flexibility and scalability with factory/adapter pattern.
- Annotated and tested with full coverage.
- Changing behaviours can be simply done by overloading/adding adapters.
- All constants class centralized in src/Interfaces can be overloaded;
👎 Cons
- do not use non free GeoLite dbs (but can be extended to do the job).
👷 Dependencies
- geoip2/geoip2
😇 Testing & Coverage
- before running tests install db doing
composer run db
- Require xdebug to enable coverage.
- Tests all passed with php version >= 7.0.
- /!\ updater tests makes real db update from maxmind, abusing leads to a 503.
Composer
Facilities run
- db (download and install db in assets db).
- test (pass all tests).
- coverage (pass all tests with coverage).
- testIp (run IpTest only).
- testDownloader (run DownloaderTest only).
- testFileManager (run FileManagerTest only).
- testUpdater (run UpdaterTest only).
- lint (check and fix source errors).
Integration
Best is with composer :
composer require pier-infor/geoliteip
To integrate the postInstall process, adjust your composer.json as below.
"scripts": { ... "post-install-cmd": [ ... "PierInfor\\GeoLite\\Installer::postInstall" ] }
Dummy app
From the root of the project, create a src folder then a file app.php inside.
Copy paste the code below in app.php
<?php namespace Company\MyApp; use PierInfor\GeoLite\Ip; error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('date.timezone', 'Europe/Paris'); ini_set('register_globals', 0); ini_set('opcache.enable', 0); if (function_exists('opcache_get_configuration')) { ini_set('opcache.memory_consumption', 128); ini_set('opcache.load_comments', true); } require_once 'vendor/autoload.php'; $geoInst = new Ip(); $forceUpdate = false; echo 'Begin update @' . microtime(true) . "\n"; $geoInst ->setAdapter(Ip::ADAPTER_ASN)->update($forceUpdate) ->setAdapter(Ip::ADAPTER_COUNTRY)->update($forceUpdate) ->setAdapter(Ip::ADAPTER_CITY)->update($forceUpdate); echo 'End update @' . microtime(true) . "\n"; $ipv6ToCheck = '2a01:e35:2422:4d60:2ad2:44ff:fe06:2983'; $ipv4ToCheck = '82.66.36.214'; echo 'Scanning ipv6 ' . $ipv6ToCheck . "\n"; echo 'Scanning ipv4 ' . $ipv4ToCheck . "\n"; $geoInst->addIp($ipv6ToCheck); $geoInst->addIp($ipv4ToCheck); echo $geoInst->process()->toJson(); unset($geoInst);
From the root of the project running
php ./src/app.php
Should be immediate with no errors and display messages as below
Begin update @1568318808.9869
End update @1568318808.9871
Scanning ipv6 2a01:e35:2422:4d60:2ad2:44ff:fe06:2983
Scanning ipv4 82.66.36.214
[
{
"ip": "2a01:e35:2422:4d60:2ad2:44ff:fe06:2983",
"country": "FR",
"city": "?",
"lon": 48.85,
"lat": 2.5,
"radius": 10
},
{
"ip": "82.66.36.214",
"country": "FR",
"city": "Aubervilliers",
"lon": 48.9163,
"lat": 2.3869,
"radius": 5
}
]
Changing forceUpdate to true will force update in silent mode.
You can figure out the accuracy changing from ipv4 to ipv6 for the same location.
🐹 Todo
- Implement input arguments to read stdin.
- Find a good php documentation generator...
pier-infor/geoliteip 适用场景与选型建议
pier-infor/geoliteip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「maxmind」 「geoip」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pier-infor/geoliteip 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pier-infor/geoliteip 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pier-infor/geoliteip 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
Ipgeobase PHP API
Geolocate IP addresses using a variety of third-party services
GeoIP package for Laravel 5.
PHP GeoIP client
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2019-11-08