PHPackages                             antikirra/uuid4 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. antikirra/uuid4

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

antikirra/uuid4
===============

3.1.1(6mo ago)014MITPHPPHP ^5.6 || ^7.0 || ^8.0

Since May 24Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/antikirra/uuid4)[ Packagist](https://packagist.org/packages/antikirra/uuid4)[ RSS](/packages/antikirra-uuid4/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

UUID4 | Fast RFC 4122 UUIDv4 Generator
======================================

[](#uuid4--fast-rfc-4122-uuidv4-generator)

[![Packagist Dependency Version](https://camo.githubusercontent.com/28f218b308d133ba98a5d4175d4da8a69a4ed9a6364a43323dc46b83ea60705e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616e74696b697272612f75756964342f706870)](https://camo.githubusercontent.com/28f218b308d133ba98a5d4175d4da8a69a4ed9a6364a43323dc46b83ea60705e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616e74696b697272612f75756964342f706870)[![Packagist Version](https://camo.githubusercontent.com/f05b10c4fececf3e83bc67e24acde2c7c4ea7fa463eeadc8055d96f0e06360ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e74696b697272612f7575696434)](https://camo.githubusercontent.com/f05b10c4fececf3e83bc67e24acde2c7c4ea7fa463eeadc8055d96f0e06360ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e74696b697272612f7575696434)

**Ultra-fast, lightweight PHP library for generating and validating RFC 4122 compliant UUIDv4 identifiers.** Perfect for distributed systems, database primary keys, and scenarios requiring cryptographically secure universally unique identifiers without external dependencies.

Install
-------

[](#install)

```
composer require antikirra/uuid4:^3.0
```

Why UUID4?
----------

[](#why-uuid4)

- ✨ **Blazing Fast Performance** - Optimized implementation with minimal overhead
- 🔧 **Universal Compatibility** - Works seamlessly from PHP 5.6 to PHP 8.4+
- 🔒 **Cryptographically Secure** - Uses secure random number generation (random\_bytes)
- 📜 **RFC 4122 Compliant** - Strictly follows official UUID version 4 specification
- 📦 **Lightweight** - Pure PHP implementation with minimal dependencies
- ✅ **Built-in Validation** - Comprehensive UUID format and variant validation
- 🚀 **Production Ready** - Battle-tested with comprehensive test coverage
- 🧪 **Fully Tested** - 100% code coverage with PHPUnit/Pest test suite

Features
--------

[](#features)

- **RFC 4122 Compliant Generation**: Creates properly formatted UUIDv4 with correct version (4) and variant bits (8, 9, a, b)
- **Cryptographic Security**: Leverages PHP's `random_bytes()` for cryptographically secure randomness
- **Strict Validation**: Validates UUID format, version, variant, and character set
- **Case-Insensitive**: Accepts both uppercase and lowercase UUID strings
- **Type Safety**: Throws exceptions for invalid input types with clear error messages
- **Legacy Support**: Compatible with ancient PHP versions (5.6+) through modern PHP 8.4
- **Zero Configuration**: Works out of the box, no setup required
- **Memory Efficient**: Minimal memory footprint, perfect for high-load applications

Perfect for
-----------

[](#perfect-for)

- **Database Primary Keys**: Alternative to auto-increment IDs in distributed databases
- **Distributed Systems**: Unique ID generation across multiple servers without coordination
- **API Development**: Request IDs, transaction tracking, resource identifiers
- **Microservices**: Service-independent unique identifiers
- **Event Sourcing**: Event IDs, aggregate identifiers
- **File Systems**: Unique file names, temporary file generation
- **Session Management**: Session tokens, correlation IDs
- **Legacy Systems**: Drop-in UUID solution for old PHP applications

Requirements
------------

[](#requirements)

- **PHP**: 5.6 or higher (tested up to PHP 8.4)
- **Extensions**: None (uses only core PHP functions)
- **Dependencies**:
    - `antikirra/random-bytes` for PHP &lt; 7.0 (provides `random_bytes()` polyfill)
    - Zero dependencies for PHP 7.0+

Basic usage
-----------

[](#basic-usage)

```
