visus/cuid2
A PHP implementation of CUID2 for generating secure, URL-safe, collision-resistant identifiers across multiple machines without coordination. Includes instance-based and static APIs plus built-in validation.
Use this assessment to make or defend the following decisions:
new Cuid2(10)) and static (Cuid2::generate(10)) APIs.VARCHAR/CHAR) with a chosen length policy; no native UUID type required. Decide a minimum length (e.g., 16–24) because 4–8 character IDs have small spaces (36⁴ ≈ 1.7M) and are unsuitable for high-volume user-facing identifiers.IdGenerator interface to make this a one-file change.Important diligence finding: the README claims sortability because a timestamp is embedded, but the timestamp is hashed into a SHA3-512 digest and base36-encoded, so CUID2 strings do not sort chronologically. Treat this as an opaque ID and always store a separate created_at indexing column. If chronological, lexicographically sortable primary keys are a hard requirement, this package is the wrong tool.
Also note: isValid() validates format only, not origin or uniqueness; IDs are not secrets and must not replace auth tokens or API keys.
Adopt when most of these are true:
uuid column or RFC 9562 interop.Look elsewhere when:
symfony/uid, ramsey/uuid).uuid types, or broad tooling support — use ramsey/uuid or symfony/uid.Executive summary. This is a low-cost, MIT-licensed PHP library that replaces hand-rolled ID code with secure, URL-safe, collision-resistant identifiers. It lets services on many machines generate IDs independently, removes a central ID service from the critical path, and stops auto-increment IDs from leaking record volumes in URLs and APIs. Cost is one Composer dependency; the main risks are a small community and single-vendor maintenance, which we mitigate with version pinning and a thin internal interface. Recommended next step: a timeboxed pilot in one service, not an org-wide standard.
For engineering. PHP 8.3 floor; install and enable GMP for a 60–306x improvement in base conversion. API is trivial: Cuid2::generate(), new Cuid2($length), Cuid2::isValid($value, expectedLength: $n). SHA3-512 hashing, secure random source, cached generation, 100% coverage claim, CI and static analysis badges. Three caveats to design around: (1) the embedded timestamp is hashed, so IDs are not chronologically sortable — add a created_at column and never sort by ID for time order; (2) isValid() is format-only, not proof of origin; (3) IDs are identifiers, not secrets.
Decision ask. Approve a two-sprint pilot behind an IdGenerator contract, with a documented minimum length policy, GMP in the container image, and a fallback plan to UUIDv7/ULID if sortable keys or standards interop become requirements.
How can I help you explore Laravel packages today?