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
Requires
- php: ^7.2
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.3 || ^8.0
- slevomat/coding-standard: ^4.8
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-10-29 00:31:52 UTC
README
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.