An implementation of Snowflake ID generator that works without a dedicated daemon.
The generator can be used with PHP-FPM
or mod_php
.
composer require ennexa/snowflake
// 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();
This generator was originally created for use on Prokerala.com.