PHPackages                             bcremer/flexihash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bcremer/flexihash

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bcremer/flexihash
=================

Library which implements consistent hashing. Modernized fork of flexihash/flexihash.

v5.0.0(1y ago)14MITPHPPHP &gt;= 8.2.0

Since Oct 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bcremer/flexihash)[ Packagist](https://packagist.org/packages/bcremer/flexihash)[ Docs](https://github.com/bremer/flexihash)[ RSS](/packages/bcremer-flexihash/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (5)Versions (8)Used By (0)

Flexihash
=========

[](#flexihash)

Flexihash is a small PHP library which implements [consistent hashing](http://en.wikipedia.org/wiki/Consistent_hashing), which is most useful in distributed caching.

Note

This repo is a fork of  which had no release since 2020. Originally authored by @pda, @dmnc and @serima

Installation
------------

[](#installation)

[Composer](https://getcomposer.org/) is the recommended installation technique. You can find flexihash on [Packagist](https://packagist.org/packages/bcremer/flexihash) so installation is as easy as

```
composer require bcremer/flexihash

```

or in your `composer.json`

```
{
    "require": {
        "bcremer/flexihash": "^5.0.0"
    }
}
```

Usage
-----

[](#usage)

```
$hash = new Flexihash();

// bulk add
$hash->addTargets(['cache-1', 'cache-2', 'cache-3']);

// simple lookup
$hash->lookup('object-a'); // "cache-1"
$hash->lookup('object-b'); // "cache-2"

// add and remove
$hash->addTarget('cache-4');
$hash->removeTarget('cache-1');

// lookup with next-best fallback (for redundant writes)
$hash->lookupList('object', 2); // ["cache-2", "cache-4"]

// remove cache-2, expect object to hash to cache-4
$hash->removeTarget('cache-2');
$hash->lookup('object'); // "cache-4"
```

Benchmarks
----------

[](#benchmarks)

Performance can be tested with [PHPBench](https://phpbench.readthedocs.io).

```
git checkout main
./vendor/bin/phpbench run --report=aggregate --iterations=4  --tag=branch_main

git checkout some-branch
./vendor/bin/phpbench run --report=aggregate --iterations=4  --ref=branch_main
```

Tests
-----

[](#tests)

### Unit Test

[](#unit-test)

```
composer test
```

### Benchmark Test

[](#benchmark-test)

```
vendor/bin/phpunit tests/BenchmarkTest.php
```

Further Reading
---------------

[](#further-reading)

-
- [http://weblogs.java.net/blog/tomwhite/archive/2007/11/consistent\_hash.html](http://weblogs.java.net/blog/tomwhite/archive/2007/11/consistent_hash.html)

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 50.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~553 days

Recently: every ~783 days

Total

7

Last Release

591d ago

Major Versions

v1.0.0 → v2.0.02015-11-08

v2.0.2 → v3.0.02020-08-07

v3.0.0 → v4.0.02024-11-18

v4.0.0 → v5.0.02024-11-20

PHP version history (3 changes)v2.0.0PHP &gt;=5.4.0

v3.0.0PHP &gt;=7.2.0

v4.0.0PHP &gt;= 8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0545dfa5917845b12373dfa688658be444a3e611aae930cc37840cf8f4acd01d?d=identicon)[bcremer](/maintainers/bcremer)

---

Top Contributors

[![dmnc](https://avatars.githubusercontent.com/u/144790?v=4)](https://github.com/dmnc "dmnc (43 commits)")[![serima](https://avatars.githubusercontent.com/u/1130921?v=4)](https://github.com/serima "serima (17 commits)")[![pda](https://avatars.githubusercontent.com/u/15759?v=4)](https://github.com/pda "pda (12 commits)")[![bcremer](https://avatars.githubusercontent.com/u/55820?v=4)](https://github.com/bcremer "bcremer (11 commits)")[![myxobek](https://avatars.githubusercontent.com/u/10741404?v=4)](https://github.com/myxobek "myxobek (1 commits)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (1 commits)")

---

Tags

consistent-hashing

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bcremer-flexihash/health.svg)

```
[![Health](https://phpackages.com/badges/bcremer-flexihash/health.svg)](https://phpackages.com/packages/bcremer-flexihash)
```

###  Alternatives

[xj/yii2-bootbox-widget

yii2-bootbox-widget

11109.0k1](/packages/xj-yii2-bootbox-widget)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
