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

v1.0.0 2025-01-26 09:26 UTC

This package is auto-updated.

Last update: 2025-09-26 11:15:31 UTC


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.