cravler/maxmind-geoip-bundle
Composer 安装命令:
composer require cravler/maxmind-geoip-bundle
包简介
Bundle integrating MaxMind GeoIP2 database into symfony application
README 文档
README
Installation
Step 1: Download the Bundle
composer require cravler/maxmind-geoip-bundle:3.x-dev
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
This bundle should be automatically enabled by Flex.
In case you don't use Flex, you'll need to manually enable the bundle by
adding the following line in the config/bundles.php file of your project:
<?php // config/bundles.php return [ // ... Cravler\MaxMindGeoIpBundle\CravlerMaxMindGeoIpBundle::class => ['all' => true], ];
Configuration
The default configuration for the bundle looks like this:
cravler_max_mind_geo_ip: client: user_id: ~ license_key: ~ options: {} path: '%kernel.project_dir%/resources/MaxMind' db: country: 'GeoIP2-Country.mmdb' city: 'GeoIP2-City.mmdb' asn: 'GeoIP2-ASN.mmdb' connection_type: 'GeoIP2-Connection-Type.mmdb' anonymous_ip: 'GeoIP2-Anonymous-IP.mmdb' enterprise: 'GeoIP2-Enterprise.mmdb' domain: 'GeoIP2-Domain.mmdb' isp: 'GeoIP2-ISP.mmdb' source: country: ~ city: ~ asn: ~ connection_type: ~ anonymous_ip: ~ enterprise: ~ domain: ~ isp: ~ md5_check: country: ~ city: ~ asn: ~ connection_type: ~ anonymous_ip: ~ enterprise: ~ domain: ~ isp: ~
If you need a GeoLite2 license:
- Sign up for a MaxMind account (no purchase required)
- Set your password and create a license key
Will this key be used for GeoIP Update? > No
# config/packages/cravler_max_mind_geo_ip.yaml parameters: max_mind.license_key: '<YOUR_LICENSE_KEY>' cravler_max_mind_geo_ip: source: country: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz&license_key=%max_mind.license_key%' city: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz&license_key=%max_mind.license_key%' asn: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&suffix=tar.gz&license_key=%max_mind.license_key%' md5_check: country: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz.md5&license_key=%max_mind.license_key%' city: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz.md5&license_key=%max_mind.license_key%' asn: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&suffix=tar.gz.md5&license_key=%max_mind.license_key%'
If you have bought a license:
# config/packages/cravler_max_mind_geo_ip.yaml parameters: max_mind.user_id: '<YOUR_USER_ID>' max_mind.license_key: '<YOUR_LICENSE_KEY>' cravler_max_mind_geo_ip: client: user_id: '%max_mind.user_id%' license_key: '%max_mind.license_key%' ... source: country: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoIP2-Country&suffix=tar.gz&license_key=%max_mind.license_key%' ... md5_check: country: ~ ...
NB! Do not forget to change your license data.
Download and update the MaxMind GeoIp2 database
php bin/console cravler:maxmind:geoip-update
You can use the --no-md5-check option if you want to skip MD5 check.
php bin/console cravler:maxmind:geoip-update --no-md5-check
How to use
Database Reader
$geoIpService = $container->get('cravler_max_mind_geo_ip.service.geo_ip_service'); // Replace "city" with the appropriate method for your database, e.g., "country". $record = $geoIpService->getRecord('128.101.101.101', 'city'); print($record->country->isoCode . "\n"); // 'US' print($record->country->name . "\n"); // 'United States' print($record->city->name . "\n"); // 'Minneapolis'
Web Service Client
$geoIpService = $container->get('cravler_max_mind_geo_ip.service.geo_ip_service'); $client = $geoIpService->getClient(); $record = $client->city('128.101.101.101');
License
This bundle is under the MIT license. See the complete license in the bundle:
LICENSE
cravler/maxmind-geoip-bundle 适用场景与选型建议
cravler/maxmind-geoip-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 627.99k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2014 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「maxmind」 「geoip2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cravler/maxmind-geoip-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cravler/maxmind-geoip-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cravler/maxmind-geoip-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
The bundle for easy using json-rpc api on your project
Ipgeobase PHP API
Geolocate IP addresses using a variety of third-party services
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 627.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 22
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-23