webmaster / maxmind-db-reader
This is the MaxMind DB Reader for Hyperf or other resident process framework. It preloads the entire mmdb file into memory, with the memory usage equal to the size of the mmdb file. It has no disk IO operations and maintains query efficiency at the microsecond level.
Installs: 1 324
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/webmaster/maxmind-db-reader
Requires
- php: >=7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.*
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: *
- phpunit/phpcov: >=6.0.0
- phpunit/phpunit: >=8.0.0,<10.0.0
- squizlabs/php_codesniffer: 3.*
Suggests
- ext-bcmath: bcmath or gmp is required for decoding larger integers with the pure PHP decoder
- ext-gmp: bcmath or gmp is required for decoding larger integers with the pure PHP decoder
- ext-maxminddb: A C-based database decoder that provides significantly faster lookups
README
Description
This is the MaxMind DB Reader for PHP Hyperf or other resident process framework. It preloads the entire mmdb file into memory, with the memory usage equal to the size of the mmdb file. It has no disk IO operations and maintains query efficiency at the microsecond level.
Install Dependencies
Run in your project root:
php composer.phar require webmaster/maxmind-db-reader:~1.0
Usage
Example
<?php namespace App\Service; use MaxMind\Db\Reader; class IpLocationService { private $reader; public function maxMind(): Reader { $dbFile = storage_path() . '/ip/GeoIP2-City.mmdb'; $dbContents = file_get_contents($dbFile, false); return new Reader($dbFile, $dbContents); } public function search(string $ip): string { if (! $this->reader) { $this->reader = $this->maxMind(); } $location = $this->reader->get($ip); return $location; } }
Support
Please report all issues with this code using the GitHub issue tracker.
Copyright and License
This software is Copyright (c) 2014-2025 by MaxMind, Inc.
Modified and developed by the Admin.IM community.