Snowflake / PHP + Rust

64-bit unique IDsgenerated in-process

Timestamp, datacenter, worker and sequence in one integer. No database, no coordinator.

Snowflake Sprite, the snowflake project pet

One class owns the whole ID lifecycle

Snowflake packs the current millisecond, datacenter, worker and a 12-bit sequence into one 64-bit integer; id() runs entirely in-process.

The core is a single stateful class, paired with one shared config file and a PSR-11 factory, so plain PHP and six frameworks share the same call.

  • 41+5+5+12 default layout
  • Sequential, random, Redis sequences
  • parseId recovers time and node
64-bitID length
4096Sequence per ms
6Framework adapters
Snowflake Sprite Smile expression

Snowflake Sprite

A blue and white snowflake sprite with six arms around a round smiling face, scattered starlight and falling snow.

Every millisecond, one ordered ID.

Everything an ID needs, in one class

Generation, clock drift handling and reverse parsing all live in the same class.

Pure PHP, zero deps

No extensions or external services; all 64-bit integer math runs in PHP.

Adjustable bit layout

Timestamp, datacenter, worker and sequence bits can be reordered to fit your scale.

Three sequence modes

Sequential, random-start and Redis-backed counters, plus a custom resolver interface.

Clock drift tolerance

Set a tolerance window, then wait for the wall clock or throw when it is exceeded.

ID reverse parsing

parseId splits an ID back into timestamp, datacenter, worker and sequence.

Six framework adapters

Laravel, Webman, ThinkPHP, Hyperf, Yii2 and Yii3 share the same core.

The same capability, in Rust

Beyond the PHP package, a pure std Rust implementation is available with zero dependencies.

Rust v2.1.0 Rust 1.88 / crate

snowflake-rust

Snowflake IDs for Rust

64-bit IDs, adjustable bits, three sequence modes and clock drift handling, zero dependencies.

  • Pure std, no deps
  • Three sequence modes
  • Eight framework adapters
View Rust repository

From generator to full adapter layer

Every entry maps to a real release.

v2.7.0

Mascot forms and social preview

Twelve ASCII mascot forms land in the Mascot class for terminals; adds a 1280x640 social preview image.

v2.6.0

Snowflake expression redraw

Redraws twelve animated SVG expressions with a unified look, palette and motion.

v2.4.0

Multilingual docs sync

Aligns READMEs and diagrams in 11 languages with the current English version, fixing several claim drifts.

v2.3.0

Static analysis and drift wait

Adds PHPStan level 8, a PSR-11 factory, the Redis sequence strategy and a waitable clock drift path.

Changelog

Recent releases; the full list is on GitHub Releases.

Latest v2.7.1 All versions
v2.7.12026-10-19

Syncs mascot and social preview docs, restores the 180px pet display.

v2.7.02026-10-18

Adds a social preview image and twelve ASCII mascot forms in code.

v2.6.12026-10-18

Removes HTML tags from the README in favor of plain Markdown.

v2.6.02026-10-18

Redraws the snowflake expression set with twelve unified animated SVGs.

v2.5.12026-10-18

Reserves commercial rights for visual assets.

v2.5.02026-09-29

Syncs docs and diagrams in 13 languages with the Yii2 and Yii3 adapters.

Install and use

Install first, then run a minimal example.

PHP >= 8.0 / 64-bit systemFull README
Install
composer require erikwang2013/snowflake-php
Minimal example
use Erikwang2013\Snowflake\Snowflake;

$snowflake = new Snowflake(workerId: 5, datacenterId: 3);
$id = $snowflake->id();
$parsed = $snowflake->parseId($id);

echo $id;

Twelve moods of the snowflake

Hover for a moment and it changes expression.

Search this site

Try “upload”, “migration” or “JWT”.