real-digital/half-flake

HalfFlake is a PHP library for distributive generating unique ID numbers using Twitter's Snowflake Algorithm

1.0.0 2019-06-28 12:33 UTC

This package is auto-updated.

Last update: 2024-04-28 23:27:26 UTC


README

Latest Stable Version Build Status Coverage Status

HalfFlake is a PHP library for distributive generating unique ID numbers using Twitter's Snowflake Algorithm.

Installation

via Composer

$ composer require real-digital/half-flake

via GitHub

$ git clone https://github.com/real-digital/half-flake.git

Usage

<?php

use Real\HalfFlake;

// an unique pair of constants defined per node
const ID_DATACENTER = 1;
const ID_NODE = 1;

$shard = new HalfFlake\Seed(ID_DATACENTER, ID_NODE);
$clock = new HalfFlake\Time();

try {
    $generator = new HalfFlake\Generator($shard, $clock);
    $id = $generator->nextId();
} catch (HalfFlake\RuntimeException $e) {
    // handle errors
}

Testing

composer test

License

HalfFlake is licensed under the MIT License. Please see LICENSE for details.

Changelog

Please see CHANGELOG for more information.