ennexa / snowflake
Snowflake ID Generator that does not require a daemon
v0.2.2
2023-06-12 10:16 UTC
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2024-12-20 17:04:30 UTC
README
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.