infocyph / uid
High-performance ID toolkit for PHP with UUID, ULID, TypeID, ObjectID, coordinated IDs, and compact ID utilities.
Requires
- php: ^8.4
- php-64bit: ^8.4
- ext-ctype: *
Requires (Dev)
- infocyph/phpforge: dev-main@dev
- infocyph/runwire: ^2.1.1
- psr/clock: ^1.0
- psr/simple-cache: ^3.0
Suggests
- infocyph/runwire: Enables request-aware cooperative waits for coordinated generators.
- psr/clock: Enables injectable wall-clock sampling for coordinated generators.
- psr/simple-cache: Required for the optional PSR-16 sequence provider.
Provides
None
Conflicts
None
Replaces
- abmmhasan/uuid: 6.0
README
All-in-one unique ID toolkit for PHP.
Features
- UUID (
v1,v3,v4,v5,v6,v7,v8) - ULID (monotonic and random modes)
- Snowflake, Sonyflake, Randflake, TBSL
- TypeID, ObjectID, NanoID, RandomId, CUID2, KSUID, XID
- Opaque and deterministic IDs
- Value objects and comparator utilities
- Binary conversion and base encoders (
10,16,32,36,58,62) - Pluggable sequence providers (filesystem, memory, PSR-16 cache, callback)
- Explicit legacy/upstream Sonyflake and Randflake compatibility modes
- Optional PSR-20 clocks and Runwire 2.1.1+ cooperative wait integration
Requirements
- PHP
>=8.4 - A 64-bit PHP runtime
- PHP ctype extension
Installation
composer require infocyph/uid
Namespaced generator functions are autoloaded via src/functions.php.
Quick Usage
<?php use Infocyph\UID\Id; use Infocyph\UID\CUID2; use Infocyph\UID\NanoID; $uuid = Id::uuid(); // default UUID strategy (v7) $ulid = Id::ulid(); $snowflake = Id::snowflake(); $sonyflake = Id::sonyflake(); $tbsl = Id::tbsl(); $randflake = \Infocyph\UID\Randflake::generate( nodeId: 42, leaseStart: time() - 5, leaseEnd: time() + 300, secret: 'super-secret-key', ); $nanoid = NanoID::generate(21); $cuid2 = CUID2::generate(24);
<?php use Infocyph\UID\UUID; $uuid = UUID::v7(); $ok = UUID::isValid($uuid); $parsed = UUID::parse($uuid); $bytes = UUID::toBytes($uuid); $roundTrip = UUID::fromBytes($bytes); $base58 = UUID::toBase($uuid, 58); $decoded = UUID::fromBase($base58, 58);
The shared byte-level encoder is available as
Infocyph\UID\Support\BaseEncoder for bases 10, 16, 32, 36, 58, and 62.
References
- UUID: https://datatracker.ietf.org/doc/html/rfc9562
- ULID: https://github.com/ulid/spec
- Snowflake: https://github.com/twitter-archive/snowflake/tree/snowflake-2010
- Sonyflake: https://github.com/sony/sonyflake
- Randflake: https://github.com/gosuda/randflake
- NanoID: https://github.com/ai/nanoid
- CUID2: https://github.com/paralleldrive/cuid2
- TBSL note: https://github.com/infocyph/UID/blob/main/TBSL.md
Security
Do not disclose suspected vulnerabilities in a public issue, discussion or pull request. Review the security policy, then use GitHub private vulnerability reporting to contact the maintainers confidentially.
UID is protected by PHPForge, an automated quality and security gate covering tests, static and taint analysis, dependency auditing, architecture checks, and release readiness. Automated controls reduce risk but do not replace responsible disclosure or manual review.
Release acceptance also runs php tests/smoke.php with a production-only install on PHP 8.4 and 8.5.
One 100-cycle pass covers every generator and supported format, checking valid output, sample uniqueness,
and relevant round trips. Long HTTP benchmarks and soak runs are not release gates.
MIT Licensed
Documentation • Security • Code of Conduct • Contributing
🗂️ Bug • Feature • Documentation • Question • CI failure
🔀 General • Bug fix • Feature • Refactor • Performance • Security & reliability • Documentation • Maintenance