ennexa/snowflake

Snowflake ID Generator that does not require a daemon

v0.1.0 2019-07-13 07:51 UTC

This package is auto-updated.

Last update: 2020-09-13 10:36:08 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.