PHPackages                             myphps/flexhash - 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. myphps/flexhash

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

myphps/flexhash
===============

Flexihash is a small PHP library which implements consistent hashing

v1.1(3y ago)05MITPHPPHP &gt;=7.0.0

Since Nov 8Pushed 3y agoCompare

[ Source](https://github.com/ncwsky/flexhash)[ Packagist](https://packagist.org/packages/myphps/flexhash)[ Docs](https://github.com/ncwsky/flexhash)[ RSS](/packages/myphps-flexhash/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Flexihash
=========

[](#flexihash)

[![Build Status](https://camo.githubusercontent.com/23c8793fb141a3dd05c386edcb3affd37ba8cc46299b33ae0bde7b2ba32e96b9/68747470733a2f2f7472617669732d63692e6f72672f7064612f666c657869686173682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pda/flexihash) [![Coverage Status](https://camo.githubusercontent.com/f89672edd0417dd38dbd61027bc80605e599f0b5e04d5e0d61643f2668e55eca/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7064612f666c657869686173682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/pda/flexihash?branch=master)

Flexihash is a small PHP library which implements [consistent hashing](http://en.wikipedia.org/wiki/Consistent_hashing), which is most useful in distributed caching. It requires PHP5 and uses [PHPUnit](http://simpletest.org/) for unit testing.

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

[](#installation)

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

```
composer require myphps/flexihash

```

or in your `composer.json`

```
{
    "require": {
        "myphps/flexhash": "^1.0"
    }
}
```

Usage
-----

[](#usage)

```
$hash = new FlexHash();

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

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

// add and remove
$hash
  ->addNode('cache-4')
  ->removeNode('cache-1');

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

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

Tests
-----

[](#tests)

### Unit Test

[](#unit-test)

```
% vendor/bin/phpunit

```

### 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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.1% 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 ~337 days

Total

2

Last Release

1315d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b74c5891fa18ea096b482ac20434e2847f4ed94292615ac6c5703251b7bd4c1?d=identicon)[ep1086](/maintainers/ep1086)

---

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)")[![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)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/myphps-flexhash/health.svg)

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

###  Alternatives

[heyday/silverstripe-hashpath

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

1475.3k](/packages/heyday-silverstripe-hashpath)

PHPackages © 2026

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