Skip to content

Latest commit

 

History

History
48 lines (28 loc) · 1.77 KB

File metadata and controls

48 lines (28 loc) · 1.77 KB

simpleflake-php

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.

Configure

Epoch

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.

Usage

<?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";

Resources

Related Projects

Articles and Presentations