PHPackages                             ada-u/chocoflake - 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. ada-u/chocoflake

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

ada-u/chocoflake
================

64bit time based id generator

v1.0.0(4y ago)14117.3k↓50%3[13 PRs](https://github.com/ada-u/chocoflake/pulls)MITPHPPHP &gt;=8.0CI passing

Since Dec 15Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/ada-u/chocoflake)[ Packagist](https://packagist.org/packages/ada-u/chocoflake)[ Docs](https://github.com/ada-u/chocoflake)[ RSS](/packages/ada-u-chocoflake/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (32)Used By (0)

chocoflake
==========

[](#chocoflake)

[![Build Status](https://camo.githubusercontent.com/3b8d145d53ba51766998a6dcb212a94a091a1cff88e438f65c008153b75d9e89/68747470733a2f2f7472617669732d63692e6f72672f6164612d752f63686f636f666c616b652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ada-u/chocoflake)[![Github Actions](https://github.com/ada-u/chocoflake/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/ada-u/chocoflake/actions/workflows/php.yml/badge.svg?branch=master)[![Coverage Status](https://camo.githubusercontent.com/3161909db04bddd2a61ae29b4095c2e4ce43645e8430dba8a938262aeacb568e/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6164612d752f63686f636f666c616b652e737667)](https://coveralls.io/r/ada-u/chocoflake?branch=master)

### 64bit ID Generator for PHP

[](#64bit-id-generator-for-php)

`chocoflake` is an implementation of twitter Snowflake concept. This provides generating IDs based on time in a distributed environment.

Usage
-----

[](#usage)

### Prerequisites

[](#prerequisites)

- PHP 8.0 or later

### Installation

[](#installation)

#### Command

[](#command)

```
$ composer.phar require ada-u/chocoflake:dev-master
```

#### composer.json

[](#composerjson)

```
{
  "require": {
    "ada-u/chocoflake": "dev-master"
  }
}
```

```
$ composer.phar install
```

### Sample

[](#sample)

Configuration

- 41 bit - for timestamp
- 5 bit - for region id
- 5 bit - for server id
- 12 bit - for sequence per milliseconds
- 1414334507356 - service start epoch (unix timestamp)

```
$config = new IdConfig(41, 5, 5, 12, 1414334507356);
$service = new ChocoflakeService($config);

$worker = $service->createIdWorkerOnSharedMemory(new RegionId(1), new ServerId(1));

$id = $worker->generate();
4194439168
```

### ID Generator

[](#id-generator)

I implemented two ID generators, Redis and SharedMemory version.

#### SharedMemory version

[](#sharedmemory-version)

Using shared memory and semaphore (as mutex) to prevent multiple processes are in the critical section at the same time.

#### Redis version

[](#redis-version)

Using Redis atomic increment operation to count up sequence.

### ID Specification

[](#id-specification)

The IDs consist of four elements:

- timestamp
- region id
- server id
- sequence

You can specify any bit length to each element.

### Test

[](#test)

```
$ docker-compose run php vendor/bin/phpunit
Creating chocoflake_php_run ... done
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 00:00.353, Memory: 6.00 MB

OK (4 tests, 4 assertions)
```

### License

[](#license)

This software is released under the MIT License, see LICENSE

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 84.8% 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 ~2404 days

Total

2

Last Release

1769d ago

Major Versions

0.0.1 → v1.0.02021-07-15

PHP version history (2 changes)0.0.1PHP &gt;=5.4.0

v1.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/474a403e037595a93adf257315b3331887c789db572f4a9f621710886a3f9c1f?d=identicon)[ada-u](/maintainers/ada-u)

---

Top Contributors

[![ada-u](https://avatars.githubusercontent.com/u/3013078?v=4)](https://github.com/ada-u "ada-u (56 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![snyk-bot](https://avatars.githubusercontent.com/u/19733683?v=4)](https://github.com/snyk-bot "snyk-bot (5 commits)")

---

Tags

generatoridchocoflakeidgen

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ada-u-chocoflake/health.svg)

```
[![Health](https://phpackages.com/badges/ada-u-chocoflake/health.svg)](https://phpackages.com/packages/ada-u-chocoflake)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[simplesoftwareio/simple-qrcode

Simple QrCode is a QR code generator made for Laravel.

2.9k27.6M92](/packages/simplesoftwareio-simple-qrcode)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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