Skip to content

HalfFlake is a PHP library for distributive generating unique ID numbers

License

Notifications You must be signed in to change notification settings

real-digital/half-flake

Repository files navigation

HalfFlake

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.

About

HalfFlake is a PHP library for distributive generating unique ID numbers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages