MediaWiki master
GlobalIdGenerator.php
Go to the documentation of this file.
1<?php
7namespace Wikimedia\UUID;
8
9use InvalidArgumentException;
10use RuntimeException;
11use Wikimedia\Assert\Assert;
12use Wikimedia\AtEase\AtEase;
13use Wikimedia\Timestamp\ConvertibleTimestamp;
14
22 protected $shellCallback;
23
25 protected $tmpDir;
32 protected $nodeIdFile;
34 protected $nodeId32;
36 protected $nodeId48;
37
39 protected $loaded = false;
41 protected $lockFile88;
43 protected $lockFile128;
45 protected $lockFileUUID;
46
48 protected $fileHandles = [];
49
54 private const FILE_PREFIX = 'mw-GlobalIdGenerator';
55
57 private const CLOCK_TIME = 'time';
59 private const CLOCK_COUNTER = 'counter';
61 private const CLOCK_SEQUENCE = 'clkSeq';
63 private const CLOCK_OFFSET = 'offset';
65 private const CLOCK_OFFSET_COUNTER = 'offsetCounter';
66
71 public function __construct( $tempDirectory, $shellCallback ) {
72 if ( func_num_args() >= 3 && !is_callable( $shellCallback ) ) {
73 trigger_error(
74 __CLASS__ . ' with a BagOStuff instance was deprecated in MediaWiki 1.37.',
75 E_USER_DEPRECATED
76 );
77 $shellCallback = func_get_arg( 2 );
78 }
79 if ( $tempDirectory === false || $tempDirectory === '' ) {
80 throw new InvalidArgumentException( "No temp directory provided" );
81 }
82 $this->tmpDir = $tempDirectory;
83 // Include the UID in the filename (T268420, T358768)
84 if ( function_exists( 'posix_geteuid' ) ) {
85 $fileSuffix = posix_geteuid();
86 } elseif ( function_exists( 'getmyuid' ) ) {
87 $fileSuffix = getmyuid();
88 } else {
89 $fileSuffix = '';
90 }
91 $this->uniqueFilePrefix = self::FILE_PREFIX . $fileSuffix;
92 $this->nodeIdFile = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-nodeid';
93 // If different processes run as different users, they may have different temp dirs.
94 // This is dealt with by initializing the clock sequence number and counters randomly.
95 $this->lockFile88 = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-88';
96 $this->lockFile128 = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-128';
97 $this->lockFileUUID = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UUID-128';
98
99 $this->shellCallback = $shellCallback;
100 }
101
117 public function newTimestampedUID88( int $base = 10 ) {
118 Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
119 Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
120
121 $info = $this->getTimeAndDelay( 'lockFile88', 1, 1024, 1024 );
122 $info[self::CLOCK_OFFSET_COUNTER] %= 1024;
123
124 return \Wikimedia\base_convert( $this->getTimestampedID88( $info ), 2, $base );
125 }
126
132 protected function getTimestampedID88( array $info ) {
133 $time = $info[self::CLOCK_TIME];
134 $counter = $info[self::CLOCK_OFFSET_COUNTER];
135 // Take the 46 LSBs of "milliseconds since epoch"
136 $id_bin = $this->millisecondsSinceEpochBinary( $time );
137 // Add a 10 bit counter resulting in 56 bits total
138 $id_bin .= str_pad( decbin( $counter ), 10, '0', STR_PAD_LEFT );
139 // Add the 32 bit node ID resulting in 88 bits total
140 $id_bin .= $this->getNodeId32();
141 // Convert to a 1-27 digit integer string
142 if ( strlen( $id_bin ) !== 88 ) {
143 throw new RuntimeException( "Detected overflow for millisecond timestamp." );
144 }
145
146 return $id_bin;
147 }
148
163 public function newTimestampedUID128( int $base = 10 ) {
164 Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
165 Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
166
167 $info = $this->getTimeAndDelay( 'lockFile128', 16384, 1_048_576, 1_048_576 );
168 $info[self::CLOCK_OFFSET_COUNTER] %= 1_048_576;
169
170 return \Wikimedia\base_convert( $this->getTimestampedID128( $info ), 2, $base );
171 }
172
178 protected function getTimestampedID128( array $info ) {
179 $time = $info[self::CLOCK_TIME];
180 $counter = $info[self::CLOCK_OFFSET_COUNTER];
181 $clkSeq = $info[self::CLOCK_SEQUENCE];
182 // Take the 46 LSBs of "milliseconds since epoch"
183 $id_bin = $this->millisecondsSinceEpochBinary( $time );
184 // Add a 20 bit counter resulting in 66 bits total
185 $id_bin .= str_pad( decbin( $counter ), 20, '0', STR_PAD_LEFT );
186 // Add a 14 bit clock sequence number resulting in 80 bits total
187 $id_bin .= str_pad( decbin( $clkSeq ), 14, '0', STR_PAD_LEFT );
188 // Add the 48 bit node ID resulting in 128 bits total
189 $id_bin .= $this->getNodeId48();
190 // Convert to a 1-39 digit integer string
191 if ( strlen( $id_bin ) !== 128 ) {
192 throw new RuntimeException( "Detected overflow for millisecond timestamp." );
193 }
194
195 return $id_bin;
196 }
197
204 public function newUUIDv1() {
205 // There can be up to 10000 intervals for the same millisecond timestamp.
206 // [0,4999] counter + [0,5000] offset is in [0,9999] for the offset counter.
207 // Add this onto the timestamp to allow making up to 5000 IDs per second.
208 return $this->getUUIDv1( $this->getTimeAndDelay( 'lockFileUUID', 16384, 5000, 5001 ) );
209 }
210
215 protected function getUUIDv1( array $info ) {
216 $clkSeq_bin = \Wikimedia\base_convert( $info[self::CLOCK_SEQUENCE], 10, 2, 14 );
217 $time_bin = $this->intervalsSinceGregorianBinary(
218 $info[self::CLOCK_TIME],
219 $info[self::CLOCK_OFFSET_COUNTER]
220 );
221 // Take the 32 bits of "time low"
222 $id_bin = substr( $time_bin, 28, 32 );
223 // Add 16 bits of "time mid" resulting in 48 bits total
224 $id_bin .= substr( $time_bin, 12, 16 );
225 // Add 4 bit version resulting in 52 bits total
226 $id_bin .= '0001';
227 // Add 12 bits of "time high" resulting in 64 bits total
228 $id_bin .= substr( $time_bin, 0, 12 );
229 // Add 2 bits of "variant" resulting in 66 bits total
230 $id_bin .= '10';
231 // Add 6 bits of "clock seq high" resulting in 72 bits total
232 $id_bin .= substr( $clkSeq_bin, 0, 6 );
233 // Add 8 bits of "clock seq low" resulting in 80 bits total
234 $id_bin .= substr( $clkSeq_bin, 6, 8 );
235 // Add the 48 bit node ID resulting in 128 bits total
236 $id_bin .= $this->getNodeId48();
237 // Convert to a 32 char hex string with dashes
238 if ( strlen( $id_bin ) !== 128 ) {
239 throw new RuntimeException( "Detected overflow for millisecond timestamp." );
240 }
241 $hex = \Wikimedia\base_convert( $id_bin, 2, 16, 32 );
242 return sprintf( '%s-%s-%s-%s-%s',
243 // "time_low" (32 bits)
244 substr( $hex, 0, 8 ),
245 // "time_mid" (16 bits)
246 substr( $hex, 8, 4 ),
247 // "time_hi_and_version" (16 bits)
248 substr( $hex, 12, 4 ),
249 // "clk_seq_hi_res" (8 bits) and "clk_seq_low" (8 bits)
250 substr( $hex, 16, 4 ),
251 // "node" (48 bits)
252 substr( $hex, 20, 12 )
253 );
254 }
255
262 public function newRawUUIDv1() {
263 return str_replace( '-', '', $this->newUUIDv1() );
264 }
265
272 public function newUUIDv4() {
273 $hex = bin2hex( random_bytes( 32 / 2 ) );
274
275 return sprintf( '%s-%s-%s-%s-%s',
276 // "time_low" (32 bits)
277 substr( $hex, 0, 8 ),
278 // "time_mid" (16 bits)
279 substr( $hex, 8, 4 ),
280 // "time_hi_and_version" (16 bits)
281 '4' . substr( $hex, 12, 3 ),
282 // "clk_seq_hi_res" (8 bits, variant is binary 10x) and "clk_seq_low" (8 bits)
283 dechex( 0x8 | ( hexdec( $hex[15] ) & 0x3 ) ) . $hex[16] . substr( $hex, 17, 2 ),
284 // "node" (48 bits)
285 substr( $hex, 19, 12 )
286 );
287 }
288
295 public function newRawUUIDv4() {
296 return str_replace( '-', '', $this->newUUIDv4() );
297 }
298
308 public function newSequentialPerNodeID( $bucket, $bits = 48 ) {
309 return current( $this->newSequentialPerNodeIDs( $bucket, $bits, 1 ) );
310 }
311
321 public function newSequentialPerNodeIDs( $bucket, $bits, $count ) {
322 return $this->getSequentialPerNodeIDs( $bucket, $bits, $count );
323 }
324
332 public function getTimestampFromUUIDv1( string $uuid, int $format = TS_MW ) {
333 $components = [];
334 if ( !preg_match(
335 '/^([0-9a-f]{8})-([0-9a-f]{4})-(1[0-9a-f]{3})-([89ab][0-9a-f]{3})-([0-9a-f]{12})$/',
336 $uuid,
337 $components
338 ) ) {
339 throw new InvalidArgumentException( "Invalid UUIDv1 {$uuid}" );
340 }
341
342 $timestamp = hexdec( substr( $components[3], 1 ) . $components[2] . $components[1] );
343 // The 60 bit timestamp value is constructed from fields of this UUID.
344 // The timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.
345 $unixTime = ( $timestamp - 0x01b21dd213814000 ) / 1e7;
346
347 return ConvertibleTimestamp::convert( $format, $unixTime );
348 }
349
360 protected function getSequentialPerNodeIDs( $bucket, $bits, $count ) {
361 if ( $count <= 0 ) {
362 return [];
363 }
364 if ( $bits < 16 || $bits > 48 ) {
365 throw new RuntimeException( "Requested bit size ($bits) is out of range." );
366 }
367
368 $path = $this->tmpDir . '/' . $this->uniqueFilePrefix . '-' . rawurlencode( $bucket ) . '-48';
369 // Get the UID lock file handle
370 if ( isset( $this->fileHandles[$path] ) ) {
371 $handle = $this->fileHandles[$path];
372 } else {
373 $handle = fopen( $path, 'cb+' );
374 $this->fileHandles[$path] = $handle ?: null;
375 }
376 // Acquire the UID lock file
377 if ( $handle === false ) {
378 throw new RuntimeException( "Could not open '{$path}'." );
379 }
380 if ( !flock( $handle, LOCK_EX ) ) {
381 fclose( $handle );
382 throw new RuntimeException( "Could not acquire '{$path}'." );
383 }
384 // Fetch the counter value and increment it...
385 rewind( $handle );
386
387 // fetch as float
388 $counter = floor( (float)trim( fgets( $handle ) ) ) + $count;
389
390 // Write back the new counter value
391 ftruncate( $handle, 0 );
392 rewind( $handle );
393
394 // Use fmod() to avoid "division by zero" on 32 bit machines
395 // warp-around as needed
396 fwrite( $handle, (string)fmod( $counter, 2 ** 48 ) );
397 fflush( $handle );
398
399 // Release the UID lock file
400 flock( $handle, LOCK_UN );
401
402 $ids = [];
403 $divisor = 2 ** $bits;
404
405 // pre-increment counter value
406 $currentId = floor( $counter - $count );
407 for ( $i = 0; $i < $count; ++$i ) {
408 // Use fmod() to avoid "division by zero" on 32 bit machines
409 $ids[] = fmod( ++$currentId, $divisor );
410 }
411
412 return $ids;
413 }
414
432 protected function getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize ) {
433 // Get the UID lock file handle
434 if ( isset( $this->fileHandles[$this->$lockFile] ) ) {
435 $handle = $this->fileHandles[$this->$lockFile];
436 } else {
437 $handle = fopen( $this->$lockFile, 'cb+' );
438 $this->fileHandles[$this->$lockFile] = $handle ?: null;
439 }
440 // Acquire the UID lock file
441 if ( $handle === false ) {
442 throw new RuntimeException( "Could not open '{$this->$lockFile}'." );
443 }
444 if ( !flock( $handle, LOCK_EX ) ) {
445 fclose( $handle );
446 throw new RuntimeException( "Could not acquire '{$this->$lockFile}'." );
447 }
448
449 // The formatters that use this method expect a timestamp with millisecond
450 // precision and a counter upto a certain size. When more IDs than the counter
451 // size are generated during the same timestamp, an exception is thrown as we
452 // cannot increment further, because the formatted ID would not have enough
453 // bits to fit the counter.
454 //
455 // To orchestrate this between independent PHP processes on the same host,
456 // we must have a common sense of time so that we only have to maintain
457 // a single counter in a single lock file.
458 //
459 // Given that:
460 // * The system clock can be observed via time(), without milliseconds.
461 // * Some other clock can be observed via microtime(), which also offers
462 // millisecond precision.
463 // * microtime() drifts in-process further and further away from the system
464 // clock the longer a process runs for.
465 // For example, on 2018-10-03 an HHVM 3.18 JobQueue process at WMF,
466 // that ran for 9 min 55 sec, microtime drifted by 7 seconds.
467 // time() does not have this problem. See https://bugs.php.net/bug.php?id=42659.
468 //
469 // We have two choices:
470 //
471 // 1. Use microtime() with the following caveats:
472 // - The last stored time may be in the future, or our current time may be in the
473 // past, in which case we'll frequently enter the slow timeWaitUntil() method to
474 // try and "sync" the current process with the previous process.
475 // We mustn't block for long though, max 10ms?
476 // - For any drift above 10ms, we pretend that the clock went backwards, and treat
477 // it the same way as after an NTP sync, by incrementing clock sequence instead.
478 // Given the sequence rolls over automatically, and silently, and is meant to be
479 // rare, this essentially sacrifices a reasonable guarantee of uniqueness.
480 // - For long running processes (e.g. longer than a few seconds) the drift can
481 // easily be more than 2 seconds. Because we only have a single lock file
482 // and don't want to keep too many counters and deal with clearing those,
483 // we fatal the user and refuse to make an ID. (T94522)
484 // - This offers terrible service availability.
485 // 2. Use time() instead, and expand the counter size by 1000x and use its
486 // digits as if they were the millisecond fraction of our timestamp.
487 // Known caveats or perf impact: None. We still need to read-write our
488 // lock file on each generation, so might as well make the most of it.
489 //
490 // We choose the latter.
491 $msecCounterSize = $counterSize * 1000;
492
493 rewind( $handle );
494 // Format of lock file contents:
495 // "<clk seq> <sec> <msec counter> <rand offset>"
496 $data = explode( ' ', fgets( $handle ) );
497
498 if ( count( $data ) === 4 ) {
499 // The UID lock file was already initialized
500 $clkSeq = (int)$data[0] % $clockSeqSize;
501 $prevSec = (int)$data[1];
502 $prevMsecCounter = (int)$data[2] % $msecCounterSize;
503 $randOffset = (int)$data[3] % $counterSize;
504 // If the system clock moved back or inter-process clock drift caused the last
505 // writer process to record a higher time than the current process time, then
506 // briefly wait for the current process clock to catch up.
507 $sec = $this->timeWaitUntil( $prevSec );
508 if ( $sec === false ) {
509 // There was too much clock drift to wait. Bump the clock sequence number to
510 // avoid collisions between new and already-generated IDs with the same time.
511 $clkSeq = ( $clkSeq + 1 ) % $clockSeqSize;
512 $sec = time();
513 $msecCounter = 0;
514 $randOffset = random_int( 0, $offsetSize - 1 );
515 trigger_error( "Clock was set back; sequence number incremented." );
516 } elseif ( $sec === $prevSec ) {
517 // The time matches the last ID. Bump the tie-breaking counter.
518 $msecCounter = $prevMsecCounter + 1;
519 if ( $msecCounter >= $msecCounterSize ) {
520 // More IDs generated with the same time than counterSize can accommodate
521 flock( $handle, LOCK_UN );
522 throw new RuntimeException( "Counter overflow for timestamp value." );
523 }
524 } else {
525 // The time is higher than the last ID. Reset the tie-breaking counter.
526 $msecCounter = 0;
527 }
528 } else {
529 // Initialize UID lock file information
530 $clkSeq = random_int( 0, $clockSeqSize - 1 );
531 $sec = time();
532 $msecCounter = 0;
533 $randOffset = random_int( 0, $offsetSize - 1 );
534 }
535
536 // Update and release the UID lock file
537 ftruncate( $handle, 0 );
538 rewind( $handle );
539 fwrite( $handle, "{$clkSeq} {$sec} {$msecCounter} {$randOffset}" );
540 fflush( $handle );
541 flock( $handle, LOCK_UN );
542
543 // Split msecCounter back into msec and counter
544 $msec = (int)( $msecCounter / 1000 );
545 $counter = $msecCounter % 1000;
546
547 return [
548 self::CLOCK_TIME => [ $sec, $msec ],
549 self::CLOCK_COUNTER => $counter,
550 self::CLOCK_SEQUENCE => $clkSeq,
551 self::CLOCK_OFFSET => $randOffset,
552 self::CLOCK_OFFSET_COUNTER => $counter + $randOffset,
553 ];
554 }
555
563 protected function timeWaitUntil( $time ) {
564 $start = microtime( true );
565 do {
566 $ct = time();
567 // https://www.php.net/manual/en/language.operators.comparison.php
568 if ( $ct >= $time ) {
569 // current time is higher than or equal to than $time
570 return $ct;
571 }
572 // up to 10ms
573 } while ( ( microtime( true ) - $start ) <= 0.010 );
574
575 return false;
576 }
577
583 protected function millisecondsSinceEpochBinary( array $time ) {
584 [ $sec, $msec ] = $time;
585 $ts = 1000 * $sec + $msec;
586 if ( $ts > 2 ** 52 ) {
587 throw new RuntimeException( __METHOD__ .
588 ': sorry, this function doesn\'t work after the year 144680' );
589 }
590
591 return substr( \Wikimedia\base_convert( (string)$ts, 10, 2, 46 ), -46 );
592 }
593
600 protected function intervalsSinceGregorianBinary( array $time, $delta = 0 ) {
601 [ $sec, $msec ] = $time;
602 $offset = '122192928000000000';
603
604 // 64 bit integers
605 if ( PHP_INT_SIZE >= 8 ) {
606 $ts = ( 1000 * $sec + $msec ) * 10000 + (int)$offset + $delta;
607 $id_bin = str_pad( decbin( $ts % ( 2 ** 60 ) ), 60, '0', STR_PAD_LEFT );
608 } elseif ( extension_loaded( 'gmp' ) ) {
609 // ms
610 $ts = gmp_add( gmp_mul( (string)$sec, '1000' ), (string)$msec );
611 // 100ns intervals
612 $ts = gmp_add( gmp_mul( $ts, '10000' ), $offset );
613 $ts = gmp_add( $ts, (string)$delta );
614 // wrap around
615 $ts = gmp_mod( $ts, gmp_pow( '2', 60 ) );
616 $id_bin = str_pad( gmp_strval( $ts, 2 ), 60, '0', STR_PAD_LEFT );
617 } elseif ( extension_loaded( 'bcmath' ) ) {
618 // ms
619 $ts = bcadd( bcmul( $sec, '1000' ), $msec );
620 // 100ns intervals
621 $ts = bcadd( bcmul( $ts, '10000' ), $offset );
622 $ts = bcadd( $ts, (string)$delta );
623 // wrap around
624 $ts = bcmod( $ts, bcpow( '2', '60' ) );
625 $id_bin = \Wikimedia\base_convert( $ts, 10, 2, 60 );
626 } else {
627 throw new RuntimeException( 'bcmath or gmp extension required for 32 bit machines.' );
628 }
629 return $id_bin;
630 }
631
635 private function load() {
636 if ( $this->loaded ) {
637 return;
638 }
639
640 $this->loaded = true;
641
642 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
643 $nodeId = @file_get_contents( $this->nodeIdFile ) ?: '';
644 // Try to get some ID that uniquely identifies this machine (RFC 4122)...
645 if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
646 AtEase::suppressWarnings();
647 if ( PHP_OS_FAMILY === 'Windows' ) {
648 // https://technet.microsoft.com/en-us/library/bb490913.aspx
649 $csv = trim( ( $this->shellCallback )( 'getmac /NH /FO CSV' ) );
650 $line = substr( $csv, 0, strcspn( $csv, "\n" ) );
651 $info = str_getcsv( $line, ",", "\"", "\\" );
652 // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal False positive
653 $nodeId = isset( $info[0] ) ? str_replace( '-', '', $info[0] ) : '';
654 } elseif ( is_executable( '/sbin/ifconfig' ) ) {
655 // Linux/BSD/Solaris/OS X
656 // See https://linux.die.net/man/8/ifconfig
657 $m = [];
658 preg_match( '/\s([0-9a-f]{2}(?::[0-9a-f]{2}){5})\s/',
659 ( $this->shellCallback )( '/sbin/ifconfig -a' ), $m );
660 $nodeId = isset( $m[1] ) ? str_replace( ':', '', $m[1] ) : '';
661 }
662 AtEase::restoreWarnings();
663 if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
664 $nodeId = bin2hex( random_bytes( 12 / 2 ) );
665 // set multicast bit
666 $nodeId[1] = dechex( hexdec( $nodeId[1] ) | 0x1 );
667 }
668 file_put_contents( $this->nodeIdFile, $nodeId );
669 }
670 $this->nodeId32 = \Wikimedia\base_convert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
671 $this->nodeId48 = \Wikimedia\base_convert( $nodeId, 16, 2, 48 );
672 }
673
677 private function getNodeId32() {
678 $this->load();
679
680 return $this->nodeId32;
681 }
682
686 private function getNodeId48() {
687 $this->load();
688
689 return $this->nodeId48;
690 }
691
703 private function deleteCacheFiles() {
704 foreach ( $this->fileHandles as $path => $handle ) {
705 if ( $handle !== null ) {
706 fclose( $handle );
707 }
708 if ( is_file( $path ) ) {
709 unlink( $path );
710 }
711 unset( $this->fileHandles[$path] );
712 }
713 if ( is_file( $this->nodeIdFile ) ) {
714 unlink( $this->nodeIdFile );
715 }
716 }
717
730 public function unitTestTearDown() {
731 $this->deleteCacheFiles();
732 }
733
734 public function __destruct() {
735 // @phan-suppress-next-line PhanPluginUseReturnValueInternalKnown
736 array_map( 'fclose', array_filter( $this->fileHandles ) );
737 }
738}
Class for getting statistically unique IDs without a central coordinator.
newRawUUIDv1()
Return an RFC4122 compliant v1 UUID.
newTimestampedUID88(int $base=10)
Get a statistically unique 88-bit unsigned integer ID string.
newTimestampedUID128(int $base=10)
Get a statistically unique 128-bit unsigned integer ID string.
newUUIDv4()
Return an RFC4122 compliant v4 UUID.
newSequentialPerNodeIDs( $bucket, $bits, $count)
Return IDs that are sequential only for this node and bucket.
newRawUUIDv4()
Return an RFC4122 compliant v4 UUID.
getSequentialPerNodeIDs( $bucket, $bits, $count)
Return IDs that are sequential only for this node and bucket.
unitTestTearDown()
Cleanup resources when tearing down after a unit test (T46850)
string $uniqueFilePrefix
File prefix containing user ID to prevent collisions if multiple users run MediaWiki (T268420) and ge...
string $tmpDir
Temporary directory.
string $nodeId32
Node ID in binary (32 bits)
string $nodeId48
Node ID in binary (48 bits)
__construct( $tempDirectory, $shellCallback)
timeWaitUntil( $time)
Wait till the current timestamp reaches $time and return the current timestamp.
bool $loaded
Whether initialization completed.
newUUIDv1()
Return an RFC4122 compliant v1 UUID.
string $lockFile128
Local file path.
array $fileHandles
Cached file handles.
getTimestampFromUUIDv1(string $uuid, int $format=TS_MW)
Get timestamp in a specified format from UUIDv1.
callable $shellCallback
Callback for running shell commands.
getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize)
Get a (time,counter,clock sequence) where (time,counter) is higher than any previous (time,...
string $lockFileUUID
Local file path.
newSequentialPerNodeID( $bucket, $bits=48)
Return an ID that is sequential only for this node and bucket.
intervalsSinceGregorianBinary(array $time, $delta=0)