PHPackages                             snaper/cruftflake - 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. snaper/cruftflake

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

snaper/cruftflake
=================

This package provides a PHP implementation of Twitter Snoflake ID Generator algoritm

0213PHP

Since Sep 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/snapercloud/cruftflake)[ Packagist](https://packagist.org/packages/snaper/cruftflake)[ RSS](/packages/snaper-cruftflake/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

CruftFlake
==========

[](#cruftflake)

[![Build Status](https://camo.githubusercontent.com/d91cff6848e6a098c31ac44773963e5e6b654c49145012d9a6ad793f13610ad3/68747470733a2f2f6170692e7472617669732d63692e6f72672f6c756361737673636e2f6372756674666c616b652e706e67)](https://travis-ci.org/lucasvscn/cruftflake)[![ProjectStatus](https://camo.githubusercontent.com/000fd996b26542f9efda86eebc78d94fce36719fdd54e687ec5de4f1761be314/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f6c756361737673636e2f6372756674666c616b652e706e67)](http://stillmaintained.com/lucasvscn/cruftflake)

A stab at a version of [Twitter Snowflake](https://github.com/twitter/snowflake)but in PHP with a simple ZeroMQ interface (rather than Thrift).

Implementation
--------------

[](#implementation)

This project was motivated by personal curiosity and also my [inability to get Twitter's project to build](https://github.com/twitter/snowflake/issues/8).

The implementation copies Twitter - generating 64 bit IDs.

- time - 41 bits
- configured machine ID - 10 bits
- sequence number - 12 bits

Has a custom epoch that means it can generate IDs until 2081-09-06 (not the same epoch as Snowflake).

### ZooKeeper for config coordination (optional)

[](#zookeeper-for-config-coordination-optional)

Each machine **must** have a unique 10 bit machine ID. ZooKeeper can be used to keep a list of all registered machine IDs, allowing new machines to self-assign a new unique machine ID.

When using ZooKeeper, when a new node starts up for the first time it **must** be able to contact the ZooKeeper cluster and create a new node. It will look at all the existing nodes and then (if it can't find its own Mac Address) attempt to claim a free one.

I was using Ephemeral nodes for this - similar(ish) to a lock pattern but this had the issue that the node needed to remain connected to ZK throughout its lifetime -- this way it doesn't.

The downside is that potentially the 1024 possible machine IDs will "fill up" and need to be manually pruned.

Running
-------

[](#running)

Git clone and then execute `composer update` to install the dependencies. You should run the tests to verify things are OK:

```
vendor/bin/phpunit

```

There are two scripts provided for playing about with.

1. The generator (the server)

    ./examples/cruftflake.php

Or to specify a manually configured machine ID:

```
./examples/cruftflake.php -m 1

```

2. A client that will generate N IDs and dump to STDOUT

    ./examples/client.php -n 100

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/51d5413f231944019df51105b95cf40ef902435959dfac24be2197d6234bd902?d=identicon)[snaper](/maintainers/snaper)

---

Top Contributors

[![lucasvscn](https://avatars.githubusercontent.com/u/3482569?v=4)](https://github.com/lucasvscn "lucasvscn (2 commits)")[![snapercloud](https://avatars.githubusercontent.com/u/17640845?v=4)](https://github.com/snapercloud "snapercloud (2 commits)")

### Embed Badge

![Health badge](/badges/snaper-cruftflake/health.svg)

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

###  Alternatives

[haruncpi/laravel-h

A helper package for Laravel Framework

477.2k](/packages/haruncpi-laravel-h)

PHPackages © 2026

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