定制 hostbrook/sypex-geo 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

hostbrook/sypex-geo

Composer 安装命令:

composer require hostbrook/sypex-geo

包简介

Get location info by IP address

README 文档

README

This extension is based on Sypex Geo free databases and lets you get the next info by IP address:

  • Country code by ISO 3166-2
  • Region code by ISO 3166-2
  • City name
  • Region name
  • Country name
  • City Latitude/Longitude data

The language requirements: PHP version >=5.3.0

The databases release date: March 16, 2025

PHP frameworks integration

You have to use Composer to add Sypex Geo to your project based on PHP frameworks like Laravel, Yii, etc.

Installation

To get the latest version via Composer:

composer require hostbrook/sypex-geo

Usage

There are two different databases that come with the extension SxGeo.dat (country database, around 814kb) and SxGeoCity.dat (city database, around 39Mb). The city database contains the same country info from the country database, but heavier. So, do not use the city database if you need to get just a country code.

Usage with country database

If you need to get just a 2-symbol country code by ISO 3166-2:

// Add namespace at the beginning of the file:
use HostBrook\SypexGeo\SypexGeo;

...

// Create an object with the country database in the argument.
// Note: By default, the country database (SxGeo.dat) is used, so it can be skipped:
$SxGeo = new SypexGeo();

// get your IP address, for example:
$userIP = $_SERVER['REMOTE_ADDR'];

// Option 1 to get the ISO country code:
$userCountry = $SxGeo->getCountry($userIP); // returns string, the country code
// Option 2  is a short equialent for country database only:
$userCountry = $SxGeo->get($userIP);        // returns string, the country code

Usage with city database

// Add namespace at the beginning of the file:
use HostBrook\SypexGeo\SypexGeo;

...

// Create an object with the city database in the argument:
$SxGeo = new SypexGeo('SxGeoCity.dat');

// Get your IP address, like an example:
$userIP = $_SERVER['REMOTE_ADDR'];

// Option 1 to get the city info:
var_dump( $SxGeo->getCity($userIP) );     // Array, the short info about a city
// Option 2 is a short equialent for the city database only:
var_dump( $SxGeo->get($userIP) );         // Array, the short info about a city

// City full info with timezone and region:
var_dump( $SxGeo->getCityFull($userIP) ); // Full info about a city

Example Data:

[
    'city' => [
        'id' => 524901,
        'lat' => 55.75222,
        'lon' => 37.61556,
        'name_ru' => 'Москва',
        'name_en' => 'Moscow',
        'okato' => '45',
    ],
    'region' => [
        'id' => 524894,
        'lat' => 55.76,
        'lon' => 37.61,
        'name_ru' => 'Москва',
        'name_en' => 'Moskva',
        'iso' => 'RU-MOW',
        'timezone' => 'Europe/Moscow',
        'okato' => '45',
    ],
    'country' => [
        'id' => 185,
        'iso' => 'RU',
        'continent' => 'EU',
        'lat' => 60,
        'lon' => 100,
        'name_ru' => 'Россия',
        'name_en' => 'Russia',
        'timezone' => 'Europe/Moscow',
    ],
];

Addition parameters

If you need to work with multiple requests to a database, you can add two parameters during object creating to use caching and packet mode:

$SxGeo = new SypexGeo('SxGeoCity.dat', SXGEO_BATCH | SXGEO_MEMORY);

it can increase a response speed.

Upgrading

Whenever there is a new release, then from the command line in your project root:

composer update

Deleting package

Running the following command will remove the package from vendor folder:

composer remove hostbrook/sypex-geo

hostbrook/sypex-geo 适用场景与选型建议

hostbrook/sypex-geo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.14k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2021 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 hostbrook/sypex-geo 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 17.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-07-04