Skip to content

Distributed ID generation in *PHP* for the lazy.

License

Notifications You must be signed in to change notification settings

traxo/simpleflake-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Distributed ID generation in *PHP* for the lazy.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%