mini\UUID\UUID7Factory class

Documentation

Generates UUID v7 identifiers using Unix timestamp (milliseconds) + cryptographically secure randomness.

UUID v7 is a 128-bit time-ordered identifier formatted as a 36-character string: xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx

Where:

  • First 48 bits: Unix timestamp in milliseconds (big-endian)
  • Next 4 bits: Version field (0111 = 7)
  • Next 12 bits: Random data (rand_a)
  • Next 2 bits: Variant field (10 = RFC 4122)
  • Last 62 bits: Random data (rand_b)

Key Benefits

  • Time-ordered: Naturally sorts by creation time (lexicographically sortable)
  • Database-friendly: Better B-tree index performance than UUID v4
  • Future-proof: Valid until year ~10889 AD
  • Unique: 74 bits of cryptographic randomness per millisecond

Specification

Implements RFC 9562 Section 5.7 https://datatracker.ietf.org/doc/rfc9562/

Example Output

018c8f3a-2b4e-7a1c-9f23-4d5e6f7a8b9c

Note: The first segment changes every ~4 days (2^32 milliseconds).

Inheritance

Implements: mini\UUID\FactoryInterface

Methods (1)

Generate a time-ordered UUID v7.

Source

src/UUID/UUID7Factory.php:38-67