PHPackages                             esi/consistent-hash - 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. esi/consistent-hash

ActiveLibrary

esi/consistent-hash
===================

ConsistentHash is a small library which implements consistent hashing. Modernized fork of flexihash/flexihash.

2.0.0(5mo ago)2201↓100%[1 issues](https://github.com/ericsizemore/consistent-hash/issues)[1 PRs](https://github.com/ericsizemore/consistent-hash/pulls)MITPHPPHP ^8.3CI passing

Since Dec 4Pushed 3d agoCompare

[ Source](https://github.com/ericsizemore/consistent-hash)[ Packagist](https://packagist.org/packages/esi/consistent-hash)[ Docs](https://github.com/ericsizemore/consistent-hash)[ GitHub Sponsors](https://github.com/ericsizemore)[ Fund](https://ko-fi.com/ericsizemore)[ RSS](/packages/esi-consistent-hash/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (12)Versions (8)Used By (0)

ConsistentHash
==============

[](#consistenthash)

[![Build Status](https://camo.githubusercontent.com/14b56aebe414cc83027a10f7cd6a31231611661e4756baad374b024d970e102e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f636f6e73697374656e742d686173682f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/ericsizemore/consistent-hash/build-status/main)[![Code Coverage](https://camo.githubusercontent.com/b2cc50eb8c0b7312351053698bb9b72ecf08adda6e5b0568fc694ed212c0d3d3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f636f6e73697374656e742d686173682f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/ericsizemore/consistent-hash/?branch=main)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/926dc3c795f2d644a839033c559339260e63c12269b247d4e38baaea2000c1ec/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f636f6e73697374656e742d686173682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/ericsizemore/consistent-hash/?branch=main)[![Continuous Integration](https://github.com/ericsizemore/consistent-hash/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/ericsizemore/consistent-hash/actions/workflows/continuous-integration.yml)[![Type Coverage](https://camo.githubusercontent.com/a8d6af038d2a0e06d82808627f598f6a5898473202ed151448c5f07c80177654/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f636f6e73697374656e742d686173682f636f7665726167652e737667)](https://shepherd.dev/github/ericsizemore/consistent-hash)[![Psalm Level](https://camo.githubusercontent.com/2e2fdc275ce81f68c3cb572e39e330ddf51f58dcb1d4f2f41a3da0accc8487c1/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f636f6e73697374656e742d686173682f6c6576656c2e737667)](https://shepherd.dev/github/ericsizemore/consistent-hash)[![Latest Stable Version](https://camo.githubusercontent.com/eef809eb8921a8fab60dbf2d77cc0de9ebb072576ce12041f23705442ce32653/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6573692f636f6e73697374656e742d686173682e737667)](https://packagist.org/packages/esi/consistent-hash)[![Downloads per Month](https://camo.githubusercontent.com/f516aa6ae70b1c4c0c5881be7a4937c9a10bc978f593f3a5c4b0a5ca83318aae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6573692f636f6e73697374656e742d686173682e737667)](https://packagist.org/packages/esi/consistent-hash)[![License](https://camo.githubusercontent.com/c2efb9ac71cf7fa8fb4c6abf95a26f04789b65f89c1ecbdbcd3a41933789b7a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6573692f636f6e73697374656e742d686173682e737667)](https://packagist.org/packages/esi/consistent-hash)

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

Note

This library is a fork of  v3.0.0. The original library has not seen any releases since 2020.

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

[](#installation)

You can install the package via composer:

```
$ composer require esi/consistent-hash
```

Usage
-----

[](#usage)

```
use Esi\ConsistentHash;

$hash = new ConsistentHash();

// 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)

#### PHPBench

[](#phpbench)

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

```
$ git clone https://github.com/ericsizemore/consistent-hash.git
$ cd consistent-hash
$ ./vendor/bin/phpbench run --report=aggregate --iterations=4 --tag=branch_main
```

Or via composer:

```
$ composer run-script benchmark
```

There is also an option to view results as a bar chart:

```
$ composer run-script benchmark:chart
```

With [opcache](https://www.php.net/manual/en/book.opcache.php) enabled:

```
# Normal, aggregate report
$ composer run-script benchmark:opcache

# Bar chart
$ composer run-script benchmark:chart:opcache
```

#### PHPUnit

[](#phpunit)

Benchmarks are also available through PHPUnit, though it is a bit more rudimentary. To see these benchmarks, run:

```
$ composer run-script phpunit:benchmark
```

About
-----

[](#about)

### Requirements

[](#requirements)

- PHP &gt;= 8.3

### Credits

[](#credits)

- [Eric Sizemore](https://github.com/ericsizemore)
- [All Contributors](https://github.com/ericsizemore/consistent-hash/contributors)

And thanks to the library this is a fork of, [flexihash/flexihash](https://github.com/pda/flexihash):

- [Paul Annesley](https://github.com/pda)
- [Dom Morgan](https://github.com/dmnc)
- [All flexihash Contributors](https://github.com/pda/flexihash/graphs/contributors)

### Contributing

[](#contributing)

See [CONTRIBUTING](./CONTRIBUTING.md).

Bugs and feature requests are tracked on [GitHub](https://github.com/ericsizemore/consistent-hash/issues).

### Contributor Covenant Code of Conduct

[](#contributor-covenant-code-of-conduct)

See [CODE\_OF\_CONDUCT.md](./CODE_OF_CONDUCT.md)

### Backward Compatibility Promise

[](#backward-compatibility-promise)

See [backward-compatibility.md](./backward-compatibility.md) for more information on Backwards Compatibility.

### Changelog

[](#changelog)

See the [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.

### License

[](#license)

See the [LICENSE](./LICENSE) for more information on the license that applies to this project.

### Roadmap/TODO

[](#roadmaptodo)

See the [ROADMAP](./ROADMAP.md) for more information what is currently being planned.

### Security

[](#security)

See [SECURITY](./SECURITY.md) for more information on the security disclosure process.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance77

Regular maintenance activity

Popularity14

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~105 days

Total

4

Last Release

159d ago

Major Versions

1.x-dev → 2.0.02025-10-14

PHP version history (2 changes)1.0.0PHP ^8.2

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7181952b087db2a847c6b90d5cc5e53948e66229ad16acf92ccca3e8767cb92?d=identicon)[ericsizemore](/maintainers/ericsizemore)

---

Top Contributors

[![ericsizemore](https://avatars.githubusercontent.com/u/723810?v=4)](https://github.com/ericsizemore "ericsizemore (179 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (157 commits)")[![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)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (1 commits)")[![myxobek](https://avatars.githubusercontent.com/u/10741404?v=4)](https://github.com/myxobek "myxobek (1 commits)")

---

Tags

consistentconsistent-hashconsistent-hashinghashphpphphashconsistentConsistent Hashingconsistent hash

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/esi-consistent-hash/health.svg)

```
[![Health](https://phpackages.com/badges/esi-consistent-hash/health.svg)](https://phpackages.com/packages/esi-consistent-hash)
```

###  Alternatives

[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67723.5k15](/packages/pestphp-pest-plugin-stressless)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

127.8k](/packages/poly-crypto-poly-crypto)

PHPackages © 2026

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