Skip to content

Ennexa/snowflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Snowflake ID Generator

An implementation of Snowflake ID generator that works without a dedicated daemon.

The generator can be used with PHP-FPM or mod_php.

Installation

composer require ennexa/snowflake

Usage

// First we need to create a store for saving the state
$store = new Snowflake\Store\RedisStore(new \Redis);
// $store = new Snowflake\Store\FileStore('/path/to/store/state');

// Create a generator with the created store
$generator = new Snowflake\Generator($store, $instanceId = 0);

// Use Generator::nextId to generate the next unique id
echo $generator->nextId();

Credits

This generator was originally created for use on Prokerala.com.

About

Snowflake ID Generator that does not require a daemon, for use with PHP-FPM

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages