MediaWiki master
GlobalIdGenerator.php
Go to the documentation of this file.
1<?php
22
23use InvalidArgumentException;
24use RuntimeException;
25use Wikimedia\Assert\Assert;
26use Wikimedia\AtEase\AtEase;
27use Wikimedia\Timestamp\ConvertibleTimestamp;
28
36 protected $shellCallback;
37
39 protected $tmpDir;
46 protected $nodeIdFile;
48 protected $nodeId32;
50 protected $nodeId48;
51
53 protected $loaded = false;
55 protected $lockFile88;
57 protected $lockFile128;
59 protected $lockFileUUID;
60
62 protected $fileHandles = [];
63
68 private const FILE_PREFIX = 'mw-GlobalIdGenerator';
69
71 private const CLOCK_TIME = 'time';
73 private const CLOCK_COUNTER = 'counter';
75 private const CLOCK_SEQUENCE = 'clkSeq';
77 private const CLOCK_OFFSET = 'offset';
79 private const CLOCK_OFFSET_COUNTER = 'offsetCounter';
80
85 public function __construct( $tempDirectory, $shellCallback ) {
86 if ( func_num_args() >= 3 && !is_callable( $shellCallback ) ) {
87 trigger_error(
88 __CLASS__ . ' with a BagOStuff instance was deprecated in MediaWiki 1.37.',
89 E_USER_DEPRECATED
90 );
91 $shellCallback = func_get_arg( 2 );
92 }
93 if ( $tempDirectory === false || $tempDirectory === '' ) {
94 throw new InvalidArgumentException( "No temp directory provided" );
95 }
96 $this->tmpDir = $tempDirectory;
97 // Include the UID in the filename (T268420, T358768)
98 if ( function_exists( 'posix_geteuid' ) ) {
99 $fileSuffix = posix_geteuid();
100 } elseif ( function_exists( 'getmyuid' ) ) {
101 $fileSuffix = getmyuid();
102 } else {
103 $fileSuffix = '';
104 }
105 $this->uniqueFilePrefix = self::FILE_PREFIX . $fileSuffix;
106 $this->nodeIdFile = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-nodeid';
107 // If different processes run as different users, they may have different temp dirs.
108 // This is dealt with by initializing the clock sequence number and counters randomly.
109 $this->lockFile88 = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-88';
110 $this->lockFile128 = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-128';
111 $this->lockFileUUID = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UUID-128';
112
113 $this->shellCallback = $shellCallback;
114 }
115
131 public function newTimestampedUID88( int $base = 10 ) {
132 Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
133 Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
134
135 $info = $this->getTimeAndDelay( 'lockFile88', 1, 1024, 1024 );
136 $info[self::CLOCK_OFFSET_COUNTER] %= 1024;
137
138 return \Wikimedia\base_convert( $this->getTimestampedID88( $info ), 2, $base );
139 }
140
146 protected function getTimestampedID88( array $info ) {
147 $time = $info[self::CLOCK_TIME];
148 $counter = $info[self::CLOCK_OFFSET_COUNTER];
149 // Take the 46 LSBs of "milliseconds since epoch"
150 $id_bin = $this->millisecondsSinceEpochBinary( $time );
151 // Add a 10 bit counter resulting in 56 bits total
152 $id_bin .= str_pad( decbin( $counter ), 10, '0', STR_PAD_LEFT );
153 // Add the 32 bit node ID resulting in 88 bits total
154 $id_bin .= $this->getNodeId32();
155 // Convert to a 1-27 digit integer string
156 if ( strlen( $id_bin ) !== 88 ) {
157 throw new RuntimeException( "Detected overflow for millisecond timestamp." );
158 }
159
160 return $id_bin;
161 }
162
177 public function newTimestampedUID128( int $base = 10 ) {
178 Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
179 Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
180
181 $info = $this->getTimeAndDelay( 'lockFile128', 16384, 1_048_576, 1_048_576 );
182 $info[self::CLOCK_OFFSET_COUNTER] %= 1_048_576;
183
184 return \Wikimedia\base_convert( $this->getTimestampedID128( $info ), 2, $base );
185 }
186
192 protected function getTimestampedID128( array $info ) {
193 $time = $info[self::CLOCK_TIME];
194 $counter = $info[self::CLOCK_OFFSET_COUNTER];
195 $clkSeq = $info[self::CLOCK_SEQUENCE];
196 // Take the 46 LSBs of "milliseconds since epoch"
197 $id_bin = $this->millisecondsSinceEpochBinary( $time );
198 // Add a 20 bit counter resulting in 66 bits total
199 $id_bin .= str_pad( decbin( $counter ), 20, '0', STR_PAD_LEFT );
200 // Add a 14 bit clock sequence number resulting in 80 bits total
201 $id_bin .= str_pad( decbin( $clkSeq ), 14, '0', STR_PAD_LEFT );
202 // Add the 48 bit node ID resulting in 128 bits total
203 $id_bin .= $this->getNodeId48();
204 // Convert to a 1-39 digit integer string
205 if ( strlen( $id_bin ) !== 128 ) {
206 throw new RuntimeException( "Detected overflow for millisecond timestamp." );
207 }
208
209 return $id_bin;
210 }
211
218 public function newUUIDv1() {
219 // There can be up to 10000 intervals for the same millisecond timestamp.
220 // [0,4999] counter + [0,5000] offset is in [0,9999] for the offset counter.
221 // Add this onto the timestamp to allow making up to 5000 IDs per second.
222 return $this->getUUIDv1( $this->getTimeAndDelay( 'lockFileUUID', 16384, 5000, 5001 ) );
223 }
224
229 protected function getUUIDv1( array $info ) {
230 $clkSeq_bin = \Wikimedia\base_convert( $info[self::CLOCK_SEQUENCE], 10, 2, 14 );
231 $time_bin = $this->intervalsSinceGregorianBinary(
232 $info[self::CLOCK_TIME],
233 $info[self::CLOCK_OFFSET_COUNTER]
234 );
235 // Take the 32 bits of "time low"
236 $id_bin = substr( $time_bin, 28, 32 );
237 // Add 16 bits of "time mid" resulting in 48 bits total
238 $id_bin .= substr( $time_bin, 12, 16 );
239 // Add 4 bit version resulting in 52 bits total
240 $id_bin .= '0001';
241 // Add 12 bits of "time high" resulting in 64 bits total
242 $id_bin .= substr( $time_bin, 0, 12 );
243 // Add 2 bits of "variant" resulting in 66 bits total
244 $id_bin .= '10';
245 // Add 6 bits of "clock seq high" resulting in 72 bits total
246 $id_bin .= substr( $clkSeq_bin, 0, 6 );
247 // Add 8 bits of "clock seq low" resulting in 80 bits total
248 $id_bin .= substr( $clkSeq_bin, 6, 8 );
249 // Add the 48 bit node ID resulting in 128 bits total
250 $id_bin .= $this->getNodeId48();
251 // Convert to a 32 char hex string with dashes
252 if ( strlen( $id_bin ) !== 128 ) {
253 throw new RuntimeException( "Detected overflow for millisecond timestamp." );
254 }
255 $hex = \Wikimedia\base_convert( $id_bin, 2, 16, 32 );
256 return sprintf( '%s-%s-%s-%s-%s',
257 // "time_low" (32 bits)
258 substr( $hex, 0, 8 ),
259 // "time_mid" (16 bits)
260 substr( $hex, 8, 4 ),
261 // "time_hi_and_version" (16 bits)
262 substr( $hex, 12, 4 ),
263 // "clk_seq_hi_res" (8 bits) and "clk_seq_low" (8 bits)
264 substr( $hex, 16, 4 ),
265 // "node" (48 bits)
266 substr( $hex, 20, 12 )
267 );
268 }
269
276 public function newRawUUIDv1() {
277 return str_replace( '-', '', $this->newUUIDv1() );
278 }
279
286 public function newUUIDv4() {
287 $hex = bin2hex( random_bytes( 32 / 2 ) );
288
289 return sprintf( '%s-%s-%s-%s-%s',
290 // "time_low" (32 bits)
291 substr( $hex, 0, 8 ),
292 // "time_mid" (16 bits)
293 substr( $hex, 8, 4 ),
294 // "time_hi_and_version" (16 bits)
295 '4' . substr( $hex, 12, 3 ),
296 // "clk_seq_hi_res" (8 bits, variant is binary 10x) and "clk_seq_low" (8 bits)
297 dechex( 0x8 | ( hexdec( $hex[15] ) & 0x3 ) ) . $hex[16] . substr( $hex, 17, 2 ),
298 // "node" (48 bits)
299 substr( $hex, 19, 12 )
300 );
301 }
302
309 public function newRawUUIDv4() {
310 return str_replace( '-', '', $this->newUUIDv4() );
311 }
312
322 public function newSequentialPerNodeID( $bucket, $bits = 48 ) {
323 return current( $this->newSequentialPerNodeIDs( $bucket, $bits, 1 ) );
324 }
325
335 public function newSequentialPerNodeIDs( $bucket, $bits, $count ) {
336 return $this->getSequentialPerNodeIDs( $bucket, $bits, $count );
337 }
338
346 public function getTimestampFromUUIDv1( string $uuid, int $format = TS_MW ) {
347 $components = [];
348 if ( !preg_match(
349 '/^([0-9a-f]{8})-([0-9a-f]{4})-(1[0-9a-f]{3})-([89ab][0-9a-f]{3})-([0-9a-f]{12})$/',
350 $uuid,
351 $components
352 ) ) {
353 throw new InvalidArgumentException( "Invalid UUIDv1 {$uuid}" );
354 }
355
356 $timestamp = hexdec( substr( $components[3], 1 ) . $components[2] . $components[1] );
357 // The 60 bit timestamp value is constructed from fields of this UUID.
358 // The timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.
359 $unixTime = ( $timestamp - 0x01b21dd213814000 ) / 1e7;
360
361 return ConvertibleTimestamp::convert( $format, $unixTime );
362 }
363
374 protected function getSequentialPerNodeIDs( $bucket, $bits, $count ) {
375 if ( $count <= 0 ) {
376 return [];
377 }
378 if ( $bits < 16 || $bits > 48 ) {
379 throw new RuntimeException( "Requested bit size ($bits) is out of range." );
380 }
381
382 $path = $this->tmpDir . '/' . $this->uniqueFilePrefix . '-' . rawurlencode( $bucket ) . '-48';
383 // Get the UID lock file handle
384 if ( isset( $this->fileHandles[$path] ) ) {
385 $handle = $this->fileHandles[$path];
386 } else {
387 $handle = fopen( $path, 'cb+' );
388 $this->fileHandles[$path] = $handle ?: null;
389 }
390 // Acquire the UID lock file
391 if ( $handle === false ) {
392 throw new RuntimeException( "Could not open '{$path}'." );
393 }
394 if ( !flock( $handle, LOCK_EX ) ) {
395 fclose( $handle );
396 throw new RuntimeException( "Could not acquire '{$path}'." );
397 }
398 // Fetch the counter value and increment it...
399 rewind( $handle );
400
401 // fetch as float
402 $counter = floor( (float)trim( fgets( $handle ) ) ) + $count;
403
404 // Write back the new counter value
405 ftruncate( $handle, 0 );
406 rewind( $handle );
407
408 // Use fmod() to avoid "division by zero" on 32 bit machines
409 // warp-around as needed
410 fwrite( $handle, (string)fmod( $counter, 2 ** 48 ) );
411 fflush( $handle );
412
413 // Release the UID lock file
414 flock( $handle, LOCK_UN );
415
416 $ids = [];
417 $divisor = 2 ** $bits;
418
419 // pre-increment counter value
420 $currentId = floor( $counter - $count );
421 for ( $i = 0; $i < $count; ++$i ) {
422 // Use fmod() to avoid "division by zero" on 32 bit machines
423 $ids[] = fmod( ++$currentId, $divisor );
424 }
425
426 return $ids;
427 }
428
446 protected function getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize ) {
447 // Get the UID lock file handle
448 if ( isset( $this->fileHandles[$this->$lockFile] ) ) {
449 $handle = $this->fileHandles[$this->$lockFile];
450 } else {
451 $handle = fopen( $this->$lockFile, 'cb+' );
452 $this->fileHandles[$this->$lockFile] = $handle ?: null;
453 }
454 // Acquire the UID lock file
455 if ( $handle === false ) {
456 throw new RuntimeException( "Could not open '{$this->$lockFile}'." );
457 }
458 if ( !flock( $handle, LOCK_EX ) ) {
459 fclose( $handle );
460 throw new RuntimeException( "Could not acquire '{$this->$lockFile}'." );
461 }
462
463 // The formatters that use this method expect a timestamp with millisecond
464 // precision and a counter upto a certain size. When more IDs than the counter
465 // size are generated during the same timestamp, an exception is thrown as we
466 // cannot increment further, because the formatted ID would not have enough
467 // bits to fit the counter.
468 //
469 // To orchestrate this between independent PHP processes on the same host,
470 // we must have a common sense of time so that we only have to maintain
471 // a single counter in a single lock file.
472 //
473 // Given that:
474 // * The system clock can be observed via time(), without milliseconds.
475 // * Some other clock can be observed via microtime(), which also offers
476 // millisecond precision.
477 // * microtime() drifts in-process further and further away from the system
478 // clock the longer a process runs for.
479 // For example, on 2018-10-03 an HHVM 3.18 JobQueue process at WMF,
480 // that ran for 9 min 55 sec, microtime drifted by 7 seconds.
481 // time() does not have this problem. See https://bugs.php.net/bug.php?id=42659.
482 //
483 // We have two choices:
484 //
485 // 1. Use microtime() with the following caveats:
486 // - The last stored time may be in the future, or our current time may be in the
487 // past, in which case we'll frequently enter the slow timeWaitUntil() method to
488 // try and "sync" the current process with the previous process.
489 // We mustn't block for long though, max 10ms?
490 // - For any drift above 10ms, we pretend that the clock went backwards, and treat
491 // it the same way as after an NTP sync, by incrementing clock sequence instead.
492 // Given the sequence rolls over automatically, and silently, and is meant to be
493 // rare, this essentially sacrifices a reasonable guarantee of uniqueness.
494 // - For long running processes (e.g. longer than a few seconds) the drift can
495 // easily be more than 2 seconds. Because we only have a single lock file
496 // and don't want to keep too many counters and deal with clearing those,
497 // we fatal the user and refuse to make an ID. (T94522)
498 // - This offers terrible service availability.
499 // 2. Use time() instead, and expand the counter size by 1000x and use its
500 // digits as if they were the millisecond fraction of our timestamp.
501 // Known caveats or perf impact: None. We still need to read-write our
502 // lock file on each generation, so might as well make the most of it.
503 //
504 // We choose the latter.
505 $msecCounterSize = $counterSize * 1000;
506
507 rewind( $handle );
508 // Format of lock file contents:
509 // "<clk seq> <sec> <msec counter> <rand offset>"
510 $data = explode( ' ', fgets( $handle ) );
511
512 if ( count( $data ) === 4 ) {
513 // The UID lock file was already initialized
514 $clkSeq = (int)$data[0] % $clockSeqSize;
515 $prevSec = (int)$data[1];
516 $prevMsecCounter = (int)$data[2] % $msecCounterSize;
517 $randOffset = (int)$data[3] % $counterSize;
518 // If the system clock moved back or inter-process clock drift caused the last
519 // writer process to record a higher time than the current process time, then
520 // briefly wait for the current process clock to catch up.
521 $sec = $this->timeWaitUntil( $prevSec );
522 if ( $sec === false ) {
523 // There was too much clock drift to wait. Bump the clock sequence number to
524 // avoid collisions between new and already-generated IDs with the same time.
525 $clkSeq = ( $clkSeq + 1 ) % $clockSeqSize;
526 $sec = time();
527 $msecCounter = 0;
528 $randOffset = random_int( 0, $offsetSize - 1 );
529 trigger_error( "Clock was set back; sequence number incremented." );
530 } elseif ( $sec === $prevSec ) {
531 // The time matches the last ID. Bump the tie-breaking counter.
532 $msecCounter = $prevMsecCounter + 1;
533 if ( $msecCounter >= $msecCounterSize ) {
534 // More IDs generated with the same time than counterSize can accommodate
535 flock( $handle, LOCK_UN );
536 throw new RuntimeException( "Counter overflow for timestamp value." );
537 }
538 } else {
539 // The time is higher than the last ID. Reset the tie-breaking counter.
540 $msecCounter = 0;
541 }
542 } else {
543 // Initialize UID lock file information
544 $clkSeq = random_int( 0, $clockSeqSize - 1 );
545 $sec = time();
546 $msecCounter = 0;
547 $randOffset = random_int( 0, $offsetSize - 1 );
548 }
549
550 // Update and release the UID lock file
551 ftruncate( $handle, 0 );
552 rewind( $handle );
553 fwrite( $handle, "{$clkSeq} {$sec} {$msecCounter} {$randOffset}" );
554 fflush( $handle );
555 flock( $handle, LOCK_UN );
556
557 // Split msecCounter back into msec and counter
558 $msec = (int)( $msecCounter / 1000 );
559 $counter = $msecCounter % 1000;
560
561 return [
562 self::CLOCK_TIME => [ $sec, $msec ],
563 self::CLOCK_COUNTER => $counter,
564 self::CLOCK_SEQUENCE => $clkSeq,
565 self::CLOCK_OFFSET => $randOffset,
566 self::CLOCK_OFFSET_COUNTER => $counter + $randOffset,
567 ];
568 }
569
577 protected function timeWaitUntil( $time ) {
578 $start = microtime( true );
579 do {
580 $ct = time();
581 // https://www.php.net/manual/en/language.operators.comparison.php
582 if ( $ct >= $time ) {
583 // current time is higher than or equal to than $time
584 return $ct;
585 }
586 // up to 10ms
587 } while ( ( microtime( true ) - $start ) <= 0.010 );
588
589 return false;
590 }
591
597 protected function millisecondsSinceEpochBinary( array $time ) {
598 [ $sec, $msec ] = $time;
599 $ts = 1000 * $sec + $msec;
600 if ( $ts > 2 ** 52 ) {
601 throw new RuntimeException( __METHOD__ .
602 ': sorry, this function doesn\'t work after the year 144680' );
603 }
604
605 return substr( \Wikimedia\base_convert( (string)$ts, 10, 2, 46 ), -46 );
606 }
607
614 protected function intervalsSinceGregorianBinary( array $time, $delta = 0 ) {
615 [ $sec, $msec ] = $time;
616 $offset = '122192928000000000';
617
618 // 64 bit integers
619 if ( PHP_INT_SIZE >= 8 ) {
620 $ts = ( 1000 * $sec + $msec ) * 10000 + (int)$offset + $delta;
621 $id_bin = str_pad( decbin( $ts % ( 2 ** 60 ) ), 60, '0', STR_PAD_LEFT );
622 } elseif ( extension_loaded( 'gmp' ) ) {
623 // ms
624 $ts = gmp_add( gmp_mul( (string)$sec, '1000' ), (string)$msec );
625 // 100ns intervals
626 $ts = gmp_add( gmp_mul( $ts, '10000' ), $offset );
627 $ts = gmp_add( $ts, (string)$delta );
628 // wrap around
629 $ts = gmp_mod( $ts, gmp_pow( '2', 60 ) );
630 $id_bin = str_pad( gmp_strval( $ts, 2 ), 60, '0', STR_PAD_LEFT );
631 } elseif ( extension_loaded( 'bcmath' ) ) {
632 // ms
633 $ts = bcadd( bcmul( $sec, '1000' ), $msec );
634 // 100ns intervals
635 $ts = bcadd( bcmul( $ts, '10000' ), $offset );
636 $ts = bcadd( $ts, (string)$delta );
637 // wrap around
638 $ts = bcmod( $ts, bcpow( '2', '60' ) );
639 $id_bin = \Wikimedia\base_convert( $ts, 10, 2, 60 );
640 } else {
641 throw new RuntimeException( 'bcmath or gmp extension required for 32 bit machines.' );
642 }
643 return $id_bin;
644 }
645
649 private function load() {
650 if ( $this->loaded ) {
651 return;
652 }
653
654 $this->loaded = true;
655
656 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
657 $nodeId = @file_get_contents( $this->nodeIdFile ) ?: '';
658 // Try to get some ID that uniquely identifies this machine (RFC 4122)...
659 if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
660 AtEase::suppressWarnings();
661 if ( PHP_OS_FAMILY === 'Windows' ) {
662 // https://technet.microsoft.com/en-us/library/bb490913.aspx
663 $csv = trim( ( $this->shellCallback )( 'getmac /NH /FO CSV' ) );
664 $line = substr( $csv, 0, strcspn( $csv, "\n" ) );
665 $info = str_getcsv( $line, ",", "\"", "\\" );
666 // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal False positive
667 $nodeId = isset( $info[0] ) ? str_replace( '-', '', $info[0] ) : '';
668 } elseif ( is_executable( '/sbin/ifconfig' ) ) {
669 // Linux/BSD/Solaris/OS X
670 // See https://linux.die.net/man/8/ifconfig
671 $m = [];
672 preg_match( '/\s([0-9a-f]{2}(?::[0-9a-f]{2}){5})\s/',
673 ( $this->shellCallback )( '/sbin/ifconfig -a' ), $m );
674 $nodeId = isset( $m[1] ) ? str_replace( ':', '', $m[1] ) : '';
675 }
676 AtEase::restoreWarnings();
677 if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
678 $nodeId = bin2hex( random_bytes( 12 / 2 ) );
679 // set multicast bit
680 $nodeId[1] = dechex( hexdec( $nodeId[1] ) | 0x1 );
681 }
682 file_put_contents( $this->nodeIdFile, $nodeId );
683 }
684 $this->nodeId32 = \Wikimedia\base_convert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
685 $this->nodeId48 = \Wikimedia\base_convert( $nodeId, 16, 2, 48 );
686 }
687
691 private function getNodeId32() {
692 $this->load();
693
694 return $this->nodeId32;
695 }
696
700 private function getNodeId48() {
701 $this->load();
702
703 return $this->nodeId48;
704 }
705
717 private function deleteCacheFiles() {
718 foreach ( $this->fileHandles as $path => $handle ) {
719 if ( $handle !== null ) {
720 fclose( $handle );
721 }
722 if ( is_file( $path ) ) {
723 unlink( $path );
724 }
725 unset( $this->fileHandles[$path] );
726 }
727 if ( is_file( $this->nodeIdFile ) ) {
728 unlink( $this->nodeIdFile );
729 }
730 }
731
744 public function unitTestTearDown() {
745 $this->deleteCacheFiles();
746 }
747
748 public function __destruct() {
749 // @phan-suppress-next-line PhanPluginUseReturnValueInternalKnown
750 array_map( 'fclose', array_filter( $this->fileHandles ) );
751 }
752}
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)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...