PHPackages                             phlib/hashstrategy - 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. phlib/hashstrategy

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

phlib/hashstrategy
==================

PHP hash strategy library including random, sorted, consistent

2.0.0(4y ago)08LGPL-3.0PHPPHP ^7.4 || ^8.0CI passing

Since Feb 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phlib/hashstrategy)[ Packagist](https://packagist.org/packages/phlib/hashstrategy)[ Docs](https://github.com/phlib/hashstrategy)[ RSS](/packages/phlib-hashstrategy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

phlib/hashstrategy
==================

[](#phlibhashstrategy)

PHP hash strategy library including random, sorted, consistent

[![Code Checks](https://camo.githubusercontent.com/4799ba282db3e979064e1dfd7c717714659f874a2cb85bd718d33932f80a8ff2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f6861736873747261746567792f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/hashstrategy/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/2ddea8d7c4d587d526dbac59014f0de3eb0c2e9f62d0b2fb62592c09cbe7fa76/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f6861736873747261746567792e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/hashstrategy)[![Latest Stable Version](https://camo.githubusercontent.com/306c70542f7e60d287dcae41d69f614bf45dad36d77b098dd91dd8a699dc9839/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f6861736873747261746567792e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/hashstrategy)[![Total Downloads](https://camo.githubusercontent.com/c11cf05e8abeb806a1bfe3b2db7c1c82b4db2e3f127705172f578cce95dd9273/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f6861736873747261746567792e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/hashstrategy)[![Licence](https://camo.githubusercontent.com/bfb8fa40e77737f5baeb67084e07291655da26262a9e80f97747f270078674b5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f6861736873747261746567792e737667)](https://camo.githubusercontent.com/bfb8fa40e77737f5baeb67084e07291655da26262a9e80f97747f270078674b5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f6861736873747261746567792e737667)

Usage
-----

[](#usage)

### Strategies

[](#strategies)

Values are added to an index with a specific weighting. They are fetched according to the strategy and the hashing `$key` passed to `get()`.

- Consistent
    - The same value(s) will always be returned for the given `$key`.
    - Weighting is used to increase the likelihood of a value being returned.
- Ordered
    - Values are returned in order of decreasing weight.
    - Values with the same weight are returned in the order added.
- Rand
    - Values are picked randomly.
    - Weighting is used to increase the likelihood of a value being returned.

```
$pool = new \Phlib\HashStrategy\Consistent();
$pool->add('one');
$pool->add('two');
$pool->add('three');
var_dump($pool->get('hello', 2));
```

### ConfigPool

[](#configpool)

Combines available hash strategies with a set of configs to provide a direct way to choose a config to use, for example choosing between a set of replicas.

```
$config = [
     'server1' => ['hostname' => 'localhost', 'port' => 11211],
     'server2' => ['hostname' => 'localhost', 'port' => 11212],
     'server3' => ['hostname' => 'localhost', 'port' => 11213],
];
$hashStrategy = new \Phlib\HashStrategy\Consistent();
$pool = new \Phlib\HashStrategy\ConfigPool($config, $hashStrategy);
var_dump($pool->getManyConfigs('some key', 2));
```

License
-------

[](#license)

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 93.2% 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 ~2442 days

Total

2

Last Release

1661d ago

Major Versions

1.0.0 → 2.0.02021-10-31

PHP version history (2 changes)1.0.0PHP ~5.4

2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/135b7ddf9ec91c412e1b18174f81d1ad2bef66e732624195c156717c96b13731?d=identicon)[letssurf](/maintainers/letssurf)

![](https://www.gravatar.com/avatar/10c53cdcfb3a6d299820aecb993521cc1a972baa09fd8f31d2468908cded7e1d?d=identicon)[chrisminett](/maintainers/chrisminett)

---

Top Contributors

[![chrisminett](https://avatars.githubusercontent.com/u/1084019?v=4)](https://github.com/chrisminett "chrisminett (41 commits)")[![jdempster](https://avatars.githubusercontent.com/u/10297?v=4)](https://github.com/jdempster "jdempster (3 commits)")

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/phlib-hashstrategy/health.svg)

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

###  Alternatives

[paragonie/blakechain

Hash chain using BLAKE2b

242.9k3](/packages/paragonie-blakechain)

PHPackages © 2026

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