Distributed ID generation in PHP for the lazy. Based on the python implementation from SawdustSoftware.
Since this algorithm has a component comprised of random bits, high-velocity sequences can actually decrease. This is generally considered an acceptable trade-off for uncoordinated vs coordinated ID generation. In practice, this is rarely an issue unless very precise ordering is key to the performance of the system implementing Simpleflake.
This implementation uses a default epoch of 2016-01-01 as of release v1.0.0
.
Increasing the epoch value decreases the base value of the generated IDs.
<?php
require "simpleflake.php";
$newId = \simpleflake\generate();
echo "ID: $newId\n";
$parts = \simpleflake\parse($newId);
echo "Timestamp: " . $parts["timestamp"] . "\n";
echo "RandomBits: " . $parts["randomBits"] . "\n";
- SawdustSoftware/simpleflake (Python)
- bwmarrin/snowflake (Golang)
- leodutra/simpleflakes (NodeJS)
- twitter/snowflake (project retired)