labor-digital/max-mind-helpers 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

labor-digital/max-mind-helpers

Composer 安装命令:

composer require labor-digital/max-mind-helpers

包简介

Helper package to implement IP to geolocation resolving based on the MaxMind database

README 文档

README

This library utilizes the free Max Mind GeoLite2 Database to perform IP => geolocation queries. The package downloads the MaxMind library to your local filesystem, so you can be sure that the client's IP will never leave your server.

The package consists of two parts. The first one is the "Downloader" which simplifies the process of "getting" the database and the "Reader" that is a wrapper around Maxmind's implementation. The reader can also cache queries to save performance using a PSR-16 SimpleCache\CacheInterface

Installation

Install this package using Composer:

composer require labor-digital/max-mind-helpers

Usage

Download the database:

<?php
use LaborDigital\MaxMindHelpers\Downloader;

// This should probably run in a cron job once a day!
$licenseKey = "YOUR LICENSE KEY";
$path = '/path/to/a/writable/directory/to/store/database';
$downloader = new Downloader($licenseKey, $path, new \GuzzleHttp\Client()); 

// This will check if an update is available based on the md5 hash of the local database
// and download the (~40MB) file only if required
$downloader->doDownloadIfRequired();

// Optional
// Always triggers a download ignoring all requirements.
$forceDownload = true;
if($forceDownload) $downloader->download();

// Get path to library file
$libraryFile = $downloader->getLibraryFile();

Use the database:

<?php
use LaborDigital\MaxMindHelpers\Reader;

// Define the path to the stored database
$path = '/path/to/a/writable/directory/to/store/database/library.mmdb';

// Get the reader
$reader = new Reader(new \MaxMind\Db\Reader($path));

// Optional
// Use the PSR-16 Cache interface to cache queries for faster lookups
$cache = new AwesomeCache(); // A class that implements \Psr\SimpleCache\CacheInterface
$reader = new Reader(new \MaxMind\Db\Reader($path), $cache);

// Get the geolocation of an ip
$location = $reader->getLocation('129.200.121.12');
// Result ['latitude' => 0.0, 'longitude' => 0.0];
// Result if query failed: NULL

// Get the geolocation of the current client's ip
$location = $reader->getLocation();
// Result's as above. If you use this at 127.0.0.1 the result will always be NULL

// Get additional information of an ip
$info = $reader->getInformation('129.200.121.12');

Further reading

Postcardware

You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: LABOR.digital - Fischtorplatz 21 - 55116 Mainz, Germany.

We publish all received postcards on our company website.

labor-digital/max-mind-helpers 适用场景与选型建议

labor-digital/max-mind-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 labor-digital/max-mind-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 labor-digital/max-mind-helpers 我们能提供哪些服务?
定制开发 / 二次开发

基于 labor-digital/max-mind-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-04-28