PHPackages                             webpatser/uuid - 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. webpatser/uuid

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

webpatser/uuid
==============

A pure PHP library to generate and validate universally unique identifiers (UUIDs) according to RFC 4122 and RFC 9562 standards. Support for UUID versions 1, 3, 4, 5, 6, 7, and 8.

v2.0.0(2mo ago)165.1k↓18.4%1MITPHPPHP ^8.5

Since Sep 10Pushed 1mo agoCompare

[ Source](https://github.com/webpatser/uuid)[ Packagist](https://packagist.org/packages/webpatser/uuid)[ Docs](https://github.com/webpatser/uuid)[ RSS](/packages/webpatser-uuid/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (8)Used By (1)

UUID Library for PHP
====================

[](#uuid-library-for-php)

[![Latest Version](https://camo.githubusercontent.com/30b16a9671066b9d5bb3f14dfe91ca45f527c8322d86d8b70936780011b6e601/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765627061747365722f757569642e737667)](https://packagist.org/packages/webpatser/uuid)[![Total Downloads](https://camo.githubusercontent.com/b8cfa0f02321a907a05e9489c52b407a1b4d6dd8d02e45a63a9863c11e2d0588/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765627061747365722f757569642e737667)](https://packagist.org/packages/webpatser/uuid)[![License](https://camo.githubusercontent.com/eeea730a454148524dd8f3deda070c6cfbeb49532b6de354a3f0a152bc244b47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7765627061747365722f757569642e737667)](https://packagist.org/packages/webpatser/uuid)

A pure PHP library to generate and validate universally unique identifiers (UUIDs) according to RFC 4122 and RFC 9562 standards. Supports UUID versions 1, 3, 4, 5, 6, 7, and 8.

**Requirements:** PHP ^8.5 (no extensions required)

Installation
------------

[](#installation)

```
composer require webpatser/uuid
```

Quick Start
-----------

[](#quick-start)

```
use Webpatser\Uuid\Uuid;

// Generate UUIDs
$uuid4 = Uuid::v4();                                    // Random (recommended for general use)
$uuid7 = Uuid::v7();                                    // Time-ordered (recommended for databases)
$uuid1 = Uuid::generate(1);                             // Time-based with MAC address
$uuid3 = Uuid::generate(3, 'example.com', Uuid::NS_DNS); // Name-based (MD5)
$uuid5 = Uuid::generate(5, 'example.com', Uuid::NS_DNS); // Name-based (SHA-1)
$uuid6 = Uuid::generate(6);                             // Reordered time-based
$uuid8 = Uuid::generate(8);                             // Custom/vendor-specific

echo (string) $uuid4; // e.g., "550e8400-e29b-41d4-a716-446655440000"
```

API Reference
-------------

[](#api-reference)

### Generation

[](#generation)

MethodDescription`Uuid::v4()`Generate random UUID (version 4)`Uuid::v7()`Generate time-ordered UUID (version 7)`Uuid::generate(int $ver, mixed $node = null, ?string $ns = null)`Generate any version (1, 3, 4, 5, 6, 7, 8)`Uuid::nil()`Create nil UUID (all zeros)### Import &amp; Validation

[](#import--validation)

MethodDescription`Uuid::import(string $uuid)`Import a UUID string`Uuid::validate(mixed $uuid)`Check if string is valid UUID format`Uuid::compare(string $a, string $b)`Compare two UUIDs (case-insensitive)`Uuid::isNilUuid(mixed $uuid)`Check if UUID is nil### Properties

[](#properties)

```
$uuid = Uuid::v7();

$uuid->string;       // "019d05e8-dfa1-7009-a8f7-4e1c868ccfa4"
$uuid->hex;          // "019d05e8dfa17009a8f74e1c868ccfa4"
$uuid->bytes;        // 16-byte binary string
$uuid->urn;          // "urn:uuid:019d05e8-dfa1-7009-a8f7-4e1c868ccfa4"
$uuid->version;      // 7
$uuid->variant;      // 1 (RFC 4122)
$uuid->time;         // 1773920640.936 (Unix timestamp, V1/V6/V7 only)
$uuid->node;         // MAC address hex (V1/V6 only, null for others)
```

### SQL Server GUID Support

[](#sql-server-guid-support)

SQL Server stores GUIDs with mixed endianness. These methods handle the byte-order conversion:

```
// Import from SQL Server
$uuid = Uuid::importFromSqlServer('825B076B-44EC-E511-80DC-00155D0ABC54');

// Export to SQL Server format
$sqlGuid = $uuid->toSqlServer();          // String format
$sqlBin  = $uuid->toSqlServerBinary();    // 16-byte binary
```

### Benchmarking

[](#benchmarking)

```
$result = Uuid::benchmark(10000, 7);
// Returns: version, iterations, total_time_ms, avg_time_us, memory_used_bytes, uuids_per_second
```

Run the benchmark script to compare versions:

```
php examples/benchmark.php 10000
```

### Name-Based UUID Namespaces

[](#name-based-uuid-namespaces)

```
Uuid::NS_DNS;   // 6ba7b810-9dad-11d1-80b4-00c04fd430c8
Uuid::NS_URL;   // 6ba7b811-9dad-11d1-80b4-00c04fd430c8
Uuid::NS_OID;   // 6ba7b812-9dad-11d1-80b4-00c04fd430c8
Uuid::NS_X500;  // 6ba7b814-9dad-11d1-80b4-00c04fd430c8
```

Features
--------

[](#features)

- UUID versions 1, 3, 4, 5, 6, 7, and 8 (RFC 4122 + RFC 9562)
- SQL Server GUID byte-order conversion
- Monotonic V7 UUIDs with 12-bit sub-millisecond sequence
- `#[\NoDiscard]` attribute on all factory and query methods
- `array_first()` PHP 8.5 native function
- `Random\Randomizer` for cryptographic random bytes
- `readonly` properties for immutability
- `match` expressions for efficient dispatching
- ~40% faster than ramsey/uuid on V4, ~45% on V7
- Zero dependencies, pure PHP

License
-------

[](#license)

MIT License.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance87

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~48 days

Total

7

Last Release

81d ago

Major Versions

v1.3.0 → v2.0.02026-03-20

PHP version history (2 changes)v1.0.0PHP ^8.2

v2.0.0PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/e442a1d15a5b64438f3b471acfded80951afb1bed23641cfd80c5254099eab9d?d=identicon)[webpatser](/maintainers/webpatser)

---

Top Contributors

[![webpatser](https://avatars.githubusercontent.com/u/25720?v=4)](https://github.com/webpatser "webpatser (16 commits)")

---

Tags

randomuuididentifierguidrfc4122rfc9562

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/webpatser-uuid/health.svg)

```
[![Health](https://phpackages.com/badges/webpatser-uuid/health.svg)](https://phpackages.com/packages/webpatser-uuid)
```

###  Alternatives

[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k729.6M3.8k](/packages/ramsey-uuid)[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.7M135](/packages/webpatser-laravel-uuid)[pascaldevink/shortuuid

PHP 7.4+ library that generates concise, unambiguous, URL-safe UUIDs

5941.8M16](/packages/pascaldevink-shortuuid)[keiko/uuid-shortener

A simple shortener library for RFC 4122 compatible UUIDs. Change your 36 chars long UUID into it's shorter equivalent.

150223.6k3](/packages/keiko-uuid-shortener)[oittaa/uuid

A small PHP class for generating RFC 9562 universally unique identifiers (UUID) from version 3 to version 8.

54316.6k6](/packages/oittaa-uuid)[ekreative/uuid-extra-bundle

Paramconverter, Normalizer and Form Type for Ramsey Uuid

18170.3k](/packages/ekreative-uuid-extra-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
