承接 globus-studio/sypexgeo 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

globus-studio/sypexgeo

Composer 安装命令:

composer require globus-studio/sypexgeo

包简介

Maintained PHP 8 reader for the SypexGeo binary IP-to-geo database (Country, City, City Max).

README 文档

README

CI License PHP

Maintained PHP 8 reader for the SypexGeo binary IP-to-geo database. Pure PHP, zero runtime dependencies, exposing a modern PSR-4 namespaced class.

Maintained by GLOBUS.studio and Yevhen Leonidov.

Features

  • Pure PHP reader for SypexGeo Country, City and City Max databases.
  • Compatible with PHP 8.1 through 8.5.
  • File, in-memory and batch lookup modes (combinable as bit flags).
  • Country, City and full City+Region+Country lookups.
  • PHPUnit test suite.

Requirements

  • PHP 8.1 or newer.
  • A SypexGeo binary database file — download from sypexgeo.net.

Installation

Composer

composer require globus-studio/sypexgeo

Manual

Copy src/SxGeo.php into your project and load it however you prefer (PSR-4 autoloader or a plain require).

Usage

use GlobusStudio\SypexGeo\SxGeo;

// Relative paths are resolved against the src/ directory — use an absolute path:
$sxgeo = new SxGeo('/absolute/path/to/SxGeoCity.dat', SxGeo::MODE_MEMORY);

$sxgeo->getCountry('8.8.8.8');     // "US"
$sxgeo->getCountryId('8.8.8.8');   // internal numeric id
$sxgeo->getCity('8.8.8.8');        // ['city' => ..., 'country' => ...]
$sxgeo->getCityFull('8.8.8.8');    // ['city' => ..., 'region' => ..., 'country' => ...]
$sxgeo->get('8.8.8.8');            // city array (City DB) or country string (Country DB)
$sxgeo->about();                   // database metadata

Lookup modes

Modes are bit flags and may be combined.

Constant Behaviour
SxGeo::MODE_FILE Read from disk on every lookup. Lowest memory.
SxGeo::MODE_MEMORY Load the whole database into RAM. Fastest reads.
SxGeo::MODE_BATCH Pre-decode indices for many sequential lookups.
MODE_MEMORY | MODE_BATCH Best throughput for bulk processing.
$sxgeo = new SxGeo('/path/to/SxGeoCity.dat', SxGeo::MODE_MEMORY | SxGeo::MODE_BATCH);

API summary

Method Returns
get(string $ip) City structure for City DB, country code for Country DB.
getCountry(string $ip) ISO 3166-1 alpha-2 country code, empty string for invalid IPs.
getCountryId(string $ip) Internal numeric country id, 0 for invalid IPs.
getCity(string $ip) ['city' => ..., 'country' => ...] or false.
getCityFull(string $ip) ['city' => ..., 'region' => ..., 'country' => ...] or false.
about() Database metadata (type, charset, sizes, timestamps).

Notes:

  • IPv4 only.
  • Private and reserved ranges (10/8, 127/8, 0/8) intentionally return false / empty.
  • The constructor throws \RuntimeException if the database is missing or has an unexpected format.

Example

See examples/lookup.php for the full script.

# Download a database from https://sypexgeo.net/en/download/
# and place it in tests/fixtures/, then:
php examples/lookup.php
SxGeo City EN  ·  utf-8  ·  5 995 121 blocks  ·  2025.12.19

8.8.8.8
  Country  US  (id: 225)
  City     Mountain View  37.3861, -122.0839
  Region   California  US-CA
  Country  United States  39.76, -98.5

Testing

composer install
composer test

The unit suite runs without any database. Integration tests are skipped automatically unless a real database is available. To run them, place a .dat file in tests/fixtures/ (see tests/fixtures/README.md).

Continuous integration

GitHub Actions runs the suite against PHP 8.1–8.5 on every push and pull request. Set the SXGEO_URL repository secret to a downloadable database URL to enable the integration suite in CI.

License

MIT, see LICENSE.

Credits

Based on the original SypexGeo library by zapimir and BINOVATOR. This fork is maintained by GLOBUS.studio and Yevhen Leonidov.

globus-studio/sypexgeo 适用场景与选型建议

globus-studio/sypexgeo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 21, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「geolocation」 「geoip」 「IP」 「sypexgeo」 「ip-to-country」 「ip-to-city」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 globus-studio/sypexgeo 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 21
  • Watchers: 15
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25