Download the PHP package dvomedia/cruftflake without Composer
On this page you can find all versions of the php package dvomedia/cruftflake. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dvomedia/cruftflake
More information about dvomedia/cruftflake
Files in dvomedia/cruftflake
Package cruftflake
Short Description CruftFlake - a stab at a version of Twitter Snowflake but in PHP with a simple ZeroMQ interface.
License MIT
Homepage https://github.com/davegardnerisme/cruftflake
Informations about the package cruftflake
CruftFlake
A stab at a version of Twitter Snowflake but in PHP with a simple ZeroMQ interface (rather than Thrift).
Implementation
This project was motivated by personal curiosity and also my inability to get Twitter's project to build.
The implementation copies Twitter - generating 64 bit IDs.
- time - 41 bits
- configured machine ID - 10 bits
- sequence number - 12 bits
Has a custom epoch that means it can generate IDs until 2081-09-06 (not the same epoch as Snowflake).
ZooKeeper for config coordination
We use ZooKeeper to store which machine IDs are in use. When a new node starts up for the first time it must be able to contact the ZooKeeper cluster and create a new node. It will look at all the existing nodes and then (if it can't find its own Mac Address) attempt to claim a free one.
I was using Ephemeral nodes for this - similar(ish) to a lock pattern but this had the issue that the node needed to remain connected to ZK throughout its lifetime -- this way it doesn't.
The downside is that potentially the 1024 possible machine IDs will "fill up" and need to be manually pruned.
Running
Installation via composer:
{
"minimum-stability": "dev",
"require": {
"posmena/cruftflake": "*"
}
}
You should run the tests to verify things are OK:
./vendor/bin/phpunit vendor/posmena/cruftflake/test/
There are two scripts provided for playing about with.
-
The generator (the server)
./scripts/cruftflake.php
-
A client that will generate N IDs and dump to STDOUT
./scripts/client.php -n 100
Dependencies*
- ZeroMQ
- ZooKeeper
*sadly these cannot be added to composer just yet!