@@ -159,6 +159,11 @@ discard block |
||
159 | 159 | return new GeneratorStatus($this->machine, $this->lastTime, $this->sequence, (PHP_INT_SIZE === 4)); |
160 | 160 | } |
161 | 161 | |
162 | + /** |
|
163 | + * @param double $timestamp |
|
164 | + * @param integer $machine |
|
165 | + * @param integer $sequence |
|
166 | + */ |
|
162 | 167 | private function mintId32($timestamp, $machine, $sequence) |
163 | 168 | { |
164 | 169 | $hi = (int) ($timestamp / pow(2, 10)); |
@@ -175,6 +180,11 @@ discard block |
||
175 | 180 | return (string) $value; |
176 | 181 | } |
177 | 182 | |
183 | + /** |
|
184 | + * @param double $timestamp |
|
185 | + * @param integer $machine |
|
186 | + * @param integer $sequence |
|
187 | + */ |
|
178 | 188 | private function mintId64($timestamp, $machine, $sequence) |
179 | 189 | { |
180 | 190 | $timestamp = (int) $timestamp; |
@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Like the Twitter one. |
|
4 | - * |
|
5 | - * 64 bits: |
|
6 | - * |
|
7 | - * time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years) |
|
8 | - * configured machine id - 10 bits - gives us up to 1024 machines |
|
9 | - * sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms) |
|
10 | - * |
|
11 | - * 32 bits + 9 = 41 bits of time |
|
12 | - * 2199023255552 < milliseconds = 2199023255 seconds |
|
13 | - * 2147483647 < max 31 bit int (signed) |
|
14 | - * |
|
15 | - * @author @davegardnerisme |
|
16 | - */ |
|
3 | + * Like the Twitter one. |
|
4 | + * |
|
5 | + * 64 bits: |
|
6 | + * |
|
7 | + * time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years) |
|
8 | + * configured machine id - 10 bits - gives us up to 1024 machines |
|
9 | + * sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms) |
|
10 | + * |
|
11 | + * 32 bits + 9 = 41 bits of time |
|
12 | + * 2199023255552 < milliseconds = 2199023255 seconds |
|
13 | + * 2147483647 < max 31 bit int (signed) |
|
14 | + * |
|
15 | + * @author @davegardnerisme |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | namespace Gendoria\CruftFlake; |
19 | 19 |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function generate() |
116 | 116 | { |
117 | - $t = floor($this->timer->getUnixTimestamp() - $this->epoch); |
|
117 | + $t = floor($this->timer->getUnixTimestamp()-$this->epoch); |
|
118 | 118 | if ($t !== $this->lastTime) { |
119 | 119 | if ($t < $this->lastTime) { |
120 | 120 | throw new UnexpectedValueException( |
121 | 121 | 'Time moved backwards. We cannot generate IDs for ' |
122 | - .($this->lastTime - $t).' milliseconds' |
|
122 | + .($this->lastTime-$t).' milliseconds' |
|
123 | 123 | ); |
124 | 124 | } elseif ($t < 0) { |
125 | 125 | throw new UnexpectedValueException( |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | private function hexdec($hex) |
187 | 187 | { |
188 | 188 | $dec = 0; |
189 | - for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) { |
|
189 | + for ($i = strlen($hex)-1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) { |
|
190 | 190 | $factor = self::$hexdec[$hex[$i]]; |
191 | 191 | $dec = bcadd($dec, bcmul($factor, $e)); |
192 | 192 | } |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Cruft flake config interface. |
|
4 | - * |
|
5 | - * Implement this if you want some other way to configure machines. |
|
6 | - * |
|
7 | - * @author @davegardnerisme |
|
8 | - */ |
|
3 | + * Cruft flake config interface. |
|
4 | + * |
|
5 | + * Implement this if you want some other way to configure machines. |
|
6 | + * |
|
7 | + * @author @davegardnerisme |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | namespace Gendoria\CruftFlake\Config; |
11 | 11 |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Fixed configuration. |
|
4 | - * |
|
5 | - * This is designed to be used where each machine **knows** what its machine |
|
6 | - * ID is - eg: via some kind of automatically deployed configuration |
|
7 | - * (puppet etc.) |
|
8 | - * |
|
9 | - * @author @davegardnerisme |
|
10 | - */ |
|
3 | + * Fixed configuration. |
|
4 | + * |
|
5 | + * This is designed to be used where each machine **knows** what its machine |
|
6 | + * ID is - eg: via some kind of automatically deployed configuration |
|
7 | + * (puppet etc.) |
|
8 | + * |
|
9 | + * @author @davegardnerisme |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace Gendoria\CruftFlake\Config; |
13 | 13 |
@@ -102,7 +102,7 @@ |
||
102 | 102 | for ($i = 0; $i < 1024, $machineId === null; ++$i) { |
103 | 103 | $machineNode = $this->machineToNode($i); |
104 | 104 | if (in_array($machineNode, $children)) { |
105 | - continue; // already used |
|
105 | + continue; // already used |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // attempt to claim |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Cruft flake timer. |
|
4 | - * |
|
5 | - * @author @davegardnerisme |
|
6 | - */ |
|
3 | + * Cruft flake timer. |
|
4 | + * |
|
5 | + * @author @davegardnerisme |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | namespace Gendoria\CruftFlake\Timer; |
9 | 9 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | * |
15 | 15 | * (Number of whole milliseconds that have passed since 1970-01-01 |
16 | 16 | * |
17 | - * @return int |
|
17 | + * @return double |
|
18 | 18 | */ |
19 | 19 | public function getUnixTimestamp() |
20 | 20 | { |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Cruft flake timer interface. |
|
4 | - * |
|
5 | - * Implement this if you want some other way to provide time. |
|
6 | - * |
|
7 | - * @author @davegardnerisme |
|
8 | - */ |
|
3 | + * Cruft flake timer interface. |
|
4 | + * |
|
5 | + * Implement this if you want some other way to provide time. |
|
6 | + * |
|
7 | + * @author @davegardnerisme |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | namespace Gendoria\CruftFlake\Timer; |
11 | 11 |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * ZeroMQ interface for cruftflake. |
|
4 | - * |
|
5 | - * @author @davegardnerisme |
|
6 | - */ |
|
3 | + * ZeroMQ interface for cruftflake. |
|
4 | + * |
|
5 | + * @author @davegardnerisme |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | namespace Gendoria\CruftFlake\Zmq; |
9 | 9 |
@@ -15,6 +15,7 @@ |
||
15 | 15 | { |
16 | 16 | /** |
17 | 17 | * Run CruftFlake server. |
18 | + * @return void |
|
18 | 19 | */ |
19 | 20 | public function run(); |
20 | 21 | } |