Unique Identifier

A unique identifier is a value that distinguishes one entity from all others within a given scope. Its uniqueness may be guaranteed within a single database table, across a distributed system, or globally.

Common forms of unique identifiers include:

  • Auto-increment integers: simple, sequential, generated by a database engine.

  • UUID, Universally Unique Identifier: 128-bit values generated without central coordination.

  • ULID, Universally Unique Lexicographically Sortable Identifier: UUID-compatible but lexicographically sortable.

  • Sqids: encodes integers into short, URL-safe strings for obfuscating sequential IDs.

  • Slug: a human-readable, URL-friendly string derived from a title or label.

The choice of identifier affects indexing performance, URL exposure, privacy as auto-increment IDs reveal record counts, and the ability to generate identifiers outside the database.

uniqid() generates a time-based string, while UUID generation is provided by libraries such as ramsey/uuid.

<?php

    // built-in, not guaranteed to be globally unique
    $id = uniqid('', true);

    // UUID via ramsey/uuid
    use Ramsey\Uuid\Uuid;
    $uuid = Uuid::uuid4()->toString();
    // e.g. 550e8400-e29b-41d4-a716-446655440000

?>

Documentation

See also ULID specification.

Related : Universally Unique IDentifier (UUID), Slug, Database, Identifier, Race Condition, Correlation ID, Idempotent, Sqids, Universally Unique Lexicographically Sortable Identifier (ULID)

Related packages : ramsey/uuid