Download the PHP package progamesigner/snowflakes without Composer
On this page you can find all versions of the php package progamesigner/snowflakes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download progamesigner/snowflakes
More information about progamesigner/snowflakes
Files in progamesigner/snowflakes
Package snowflakes
Short Description A decentralized, k-ordered UUID generator in PHP
License MIT
Informations about the package snowflakes
Snowflakes
Snowflakes is a PHP and Composer package that provides:
- A simple 128-bit id generator.
- Methods to convert snowflakes ID into string
Snowflakes produces 128-bit and time-ordered ids. They run one on each node in infrastructure and will generate conflict-free ids on-demand without coordination.
The project is inspired by Twitter's Snowflake and Go implementation of Discord but extended to 128-bit and not compatible with Twitter's Snowflake. This library provides a basis for id generation but not a service for handing out ids nor node id coordination.
Getting Started
Installation
Usage
If you are using Laravel, you can use SnowflakesServiceProvider
shipped with this package. Configure worker id
with config('services.snowflakes.id', $worker_id)
and get snowflake with resolve('snowflakes')->next()
.
Format
Snowflakes ids are 128-bits wide described here from most significant to least significant bits:
- timestamp (64-bit) - milliseconds since the epoch (Jan 1 1970)
- node id(48-bit) - a configurable node id
- sequence (16-bit) - usually 0, increasing when more than one request in the same millisecond and reset to 0 when clock ticks forward
System Clock Dependency
You should use NTP to keep your system clock accurate. Snowflakes holds requests when non-monotonic clock detected. To run in a mode where NTP not move the clock backwards, see http://wiki.dovecot.org/TimeMovedBackwards#Time_synchronization for tips on how to do this.
Related Projects
Maintainers
Contribute
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that I can review your changes
License
MIT © Yang Sheng Han