PHPackages                             chxj1992/hashring - 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. chxj1992/hashring

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

chxj1992/hashring
=================

Consistent hashing "hashring" implementation in php (using the same algorithm as libketama)

v1.0.1(9y ago)672.4k↓44%2[1 PRs](https://github.com/chxj1992/hashring/pulls)MITPHPPHP &gt;=5.4.0

Since Feb 19Pushed 4y ago2 watchersCompare

[ Source](https://github.com/chxj1992/hashring)[ Packagist](https://packagist.org/packages/chxj1992/hashring)[ RSS](/packages/chxj1992-hashring/feed)WikiDiscussions master Synced yesterday

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

HashRing [![Build Status](https://camo.githubusercontent.com/dddaf607a56ef939be056f1465391e3fd48b709be08ce0af3bcd7f0fec7eaedf/68747470733a2f2f7472617669732d63692e6f72672f6368786a313939322f6861736872696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chxj1992/hashring)
===========================================================================================================================================================================================================================================================================================

[](#hashring--)

[![WTFPL](https://camo.githubusercontent.com/4051644883ab2869f11be71537ea53f57bbb44f1dfa2da471ab524f02f87b331/687474703a2f2f7777772e777466706c2e6e65742f77702d636f6e74656e742f75706c6f6164732f323031322f31322f777466706c2d62616467652d342e706e67)](http://www.wtfpl.net/)

Implements consistent hashing that can be used when the number of server nodes can increase or decrease (like in memcached). The hashing ring is built using the same algorithm as libketama.

Inspired by a golang hashring library [serialx/hashring](https://github.com/serialx/hashring).

Using
=====

[](#using)

Install ::

```
composer require chxj1992/hashring:~1.0
```

Basic example usage ::

```
$memcacheServers = ["192.168.0.246:11212",
                    "192.168.0.247:11212",
                    "192.168.0.249:11212"];

$hashRing = new \Chxj1992\HashRing\HashRing($memcacheServers);
$server = $ring->getNode("my_key");
```

Using weights example ::

```
$weights = ["192.168.0.246:11212" => 1,
            "192.168.0.247:11212" => 2,
            "192.168.0.249:11212" => 1];

$hashRing = new \Chxj1992\HashRing\HashRing($weights);
$server = $hashRing->getNode("my_key");
```

Adding and removing nodes example ::

```
$memcacheServers = ["192.168.0.246:11212",
                    "192.168.0.247:11212",
                    "192.168.0.249:11212"];

$hashRing = new \Chxj1992\HashRing\HashRing($memcacheServers);
$hashRing = $hashRing->removeNode("192.168.0.246:11212");
$hashRing = $hashRing->addNode("192.168.0.250:11212");
$server = $hashRing->getNode("my_key");
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

3421d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f26bba3366c07cce68426161ade309dceef21587090b566647b4b82c4697292?d=identicon)[chxj1992](/maintainers/chxj1992)

---

Top Contributors

[![chxj1992](https://avatars.githubusercontent.com/u/1113743?v=4)](https://github.com/chxj1992 "chxj1992 (12 commits)")

---

Tags

consistent-hashinghashringlibketamaphpphpConsistent Hashinglibketama

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chxj1992-hashring/health.svg)

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

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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