~/docs
Resonate
Resonate
3.x 3.0.0, current
ULID
Toggle sidebar
ULID
webpatser/ulid 3.0.0

ULID 3.x

Quick Start

Generate, parse and validate ULIDs with the Ulid class.

Everything lives in one class, Webpatser\Ulid\Ulid.

use Webpatser\Ulid\Ulid;
 
// Generate a ULID
$ulid = Ulid::generate();
echo (string) $ulid; // e.g., "01ARZ3NDEKTSV4RRFFQ69G5FAV"
 
// Generate with a specific timestamp
$ulid = Ulid::generate(new DateTimeImmutable('2024-01-15 12:00:00'));
 
// Parse an existing ULID
$ulid = Ulid::fromString('01ARZ3NDEKTSV4RRFFQ69G5FAV');
 
// Validate
Ulid::isValid('01ARZ3NDEKTSV4RRFFQ69G5FAV'); // true
Ulid::isValid('not-a-ulid'); // false

The format

  • 26 characters, Crockford Base32 encoded (0-9, A-H, J-K, M-N, P-T, V-Z).
  • A 48-bit millisecond timestamp (first 10 characters) followed by 80 bits of randomness (last 16 characters).
  • Monotonic: multiple ULIDs within the same millisecond increment the random portion.
  • Lexicographically sortable: string comparison preserves chronological order.
  • Binary compatible: 16 bytes, the same size as a UUID, so it fits in BINARY(16) columns.
  • Case insensitive when parsing: fromString() and isValid() accept upper and lowercase.

Features

  • #[\NoDiscard] on all factory and query methods, so PHP warns when a result is ignored.
  • Random\Randomizer supplies the random bytes.
  • The 16 bytes are held in a readonly property.
  • Bidirectional UUID conversion through webpatser/uuid.

Try it

Generate a ULID or a batch of up to 20. Each one comes from Ulid::generate() on this server, and the batch shows that string order is creation order.

How many

Ulid::generate(), called 1 time on this server just now, listed in creation order.

  1. 1 01M86YFXMTBV8M3YBRG1GVCYA7

Batches run on demand, at most 20 a minute per visitor.

Inspect a ULID

Paste a ULID to validate it and read its timestamp and UUID form, or paste a UUID to convert it with Ulid::fromUuid().

ULID or UUID Paste a ULID to decode it, or a UUID to convert it to a ULID.
Valid ULID, parsed with Ulid::fromString().
(string) $ulid
01ARZ3NDEKTSV4RRFFQ69G5FAV
$ulid->getTimestamp()
2016-07-30 23:54:10.259 UTC
$ulid->getTimestampMs()
1469922850259
(string) $ulid->toUuid()
01563e3a-b5d3-d676-4c61-efb99302bd5b
bin2hex($ulid->toBytes())
01563e3ab5d3d6764c61efb99302bd5b

See Examples and the API reference.