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

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

rafalswierczek/uuid
===================

Super simple UUID generator in PHP

2.2(6mo ago)65MITPHPPHP ^8.3CI passing

Since Jul 29Pushed 6mo ago1 watchersCompare

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

READMEChangelog (9)Dependencies (5)Versions (10)Used By (0)

Simple and fast UUID generator in PHP
=====================================

[](#simple-and-fast-uuid-generator-in-php)

[![Build](https://github.com/rafalswierczek/uuid/actions/workflows/php.yml/badge.svg)](https://github.com/rafalswierczek/uuid/actions/workflows/php.yml)

Installation:
-------------

[](#installation)

> composer require rafalswierczek/uuid

Requirements:
-------------

[](#requirements)

- PHP 8.3 with x64 architecture
- FFI (only for `Uuid4::createManyFfi`)

Usage:
------

[](#usage)

UUID v4:

```
// basic usage:
$uuid4Static = Uuid4::create();
$uuid4New = new Uuid4('f3d7fa06-d938-4c22-9505-c585efa381df');
$valid = Uuid4::validate('f3d7fa06-d938-4c22-9505-c585efa381df');
$equals = $uuid4New->equals($uuid4Static);
$uuidList = Uuid4::createManyFfi(1000000);

// example: create random user id used by other services
$userExternalId = Uuid4::create();
```

UUID v5:

```
// basic usage:
$uuid5Static = Uuid5::create(Uuid4::create(), 'seed');
$uuid5New = new Uuid5('0bfa18dd-3e8a-5810-b9b2-336b56af84b2');
$valid = Uuid5::validate('0bfa18dd-3e8a-5810-b9b2-336b56af84b2');
$equals = $uuid5New->equals($uuid5Static);

// example: get support tickets very fast based on query params
$standardNamespace = new Uuid1(Uuid5::NAMESPACE_DNS);
$yourAppNamespace = Uuid5::create($standardNamespace, 'internal.it-helpdesk.org');
$searchParams = json_encode([
    'from' => '2025-01-30 12:35',
    'department' => 'it',
    'type' => 'bug',
]);
$searchHash = Uuid5::create($yourAppNamespace, $searchParams);
$tickets = $cache->get($searchHash, function (ItemInterface $item) use ($searchParams): array {
    return getTickets($searchParams);
});
```

UUID v7:

```
// basic usage:
$uuid7Static = Uuid7::create();
$uuid7New = new Uuid7('0199d59e-8041-7b74-b74e-b94310cd9473');
$valid = Uuid7::validate('0199d59e-8041-7b74-b74e-b94310cd9473');
$equals = $uuid7Static->equals($uuid7New);

// example: create indexable/monotonic list of events
$eventStream = [];
$eventStream[] = new UserCreatedEvent(id: Uuid7::create(), name: 'John');
$eventStream[] = new UserCreatedEvent(id: Uuid7::create(), name: 'Alice');
$eventStream[] = new UserCreatedEvent(id: Uuid7::create(), name: 'Bob');
$eventStream[] = new UserCreatedEvent(id: Uuid7::create(), name: 'Adam');
persistEvents($eventStream);
// let's say Alice id is 0199d59e-8041-7b74-b74e-b94310cd9473
$events = $this->query("SELECT * FROM event_log WHERE id > '0199d59e-8041-7b74-b74e-b94310cd9473'");
foreach ($events as $event) {
    echo $event->name.' ';
}
// Bob Adam
```

Performance
-----------

[](#performance)

#### UUID v4 generation performance:

[](#uuid-v4-generation-performance)

LibraryAmountTimeMemory usagerafalswierczek5000000020.41 sec7.09 GiBsymfony5000000022.74 sec8.95 GiBramsey5000000043.59 sec8.95 GiBLibraryAmountTimeMemory usagerafalswierczek1000000314.60 ms131.24 MiBsymfony1000000328.46 ms169.39 MiBramsey1000000805.66 ms169.39 MiBLibraryAmountTimeMemory usagerafalswierczek1000284.54 µs137.32 KiBsymfony1000300.62 µs176.38 KiBramsey1000716.17 µs176.38 KiBLibraryAmountTimeMemory usagerafalswierczek10.39 µs352.00 Bsymfony10.35 µs376.00 Bramsey10.80 µs376.00 B---

#### UUID v5 generation performance:

[](#uuid-v5-generation-performance)

LibraryAmountTimeMemory usagerafalswierczek5000000045.28 sec19.01 GiBsymfony5000000036.57 sec8.95 GiBramsey5000000048.59 sec8.95 GiBLibraryAmountTimeMemory usagerafalswierczek1000000589.02 ms375.38 MiBsymfony1000000582.31 ms169.39 MiBramsey1000000814.87 ms169.39 MiBLibraryAmountTimeMemory usagerafalswierczek1000548.62 µs387.32 KiBsymfony1000550.67 µs176.38 KiBramsey1000783.83 µs176.38 KiBLibraryAmountTimeMemory usagerafalswierczek10.60 µs592.00 Bsymfony10.61 µs376.00 Bramsey10.85 µs376.00 B---

#### UUID v7 generation performance:

[](#uuid-v7-generation-performance)

LibraryAmountTime secondsAmount in 1msMemory usagerafalswierczek5000000041.50 sec129519.01 GiBsymfony5000000044.33 sec11828.95 GiBramsey5000000068.32 sec7558.95 GiBLibraryAmountTime secondsAmount in 1msMemory usagerafalswierczek1000000515.38 ms2006375.38 MiBsymfony1000000802.43 ms1317169.39 MiBramsey10000001.16 sec875169.39 MiBLibraryAmountTime secondsAmount in 1msMemory usagerafalswierczek1000478.80 µs770387.32 KiBsymfony1000678.17 µs665176.38 KiBramsey10001.12 ms477176.38 KiBLibraryAmountTime secondsAmount in 1msMemory usagerafalswierczek10.53 µs1592.00 Bsymfony10.77 µs1376.00 Bramsey11.23 µs1376.00 BMonotonicity of UUID v7
-----------------------

[](#monotonicity-of-uuid-v7)

Implementation of UUID v7 in this library supports monotonicity (Method 3 [RFC 9562](https://www.rfc-editor.org/rfc/rfc9562.html#name-monotonicity-and-counters))

Compilation of UUID v4 C code
-----------------------------

[](#compilation-of-uuid-v4-c-code)

Windows `ggcc -shared -O3 -o ../include/nwuuid4.dll uuid4_win_x64.c -lbcrypt`

Linux `gcc -shared -fPIC -O3 -s -o ../include/nwuuid4.so uuid4_linux_x64.c`

Running performance tests
-------------------------

[](#running-performance-tests)

Each test case includes a CPU warm-up phase and a specific number of attempts, with average values provided as the result. Additionally, I suggest running each test case 3 times to calculate an average of the averages for maximum precision. Each test case should be executed separately, as this approach provides the most accurate results.

UUID v4:

```
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid4Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid4Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid4Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid4Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid4Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid4Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid4Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid4Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid4Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid4Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid4Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid4Ramsey"

```

UUID v5:

```
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid5Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid5Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid5Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid5Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid5Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid5Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid5Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid5Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid5Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid5Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid5Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid5Ramsey"

```

UUID v7:

```
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid7Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid7Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1Uuid7Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid7Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid7Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1KUuid7Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid7Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid7Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate1MUuid7Ramsey"

php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid7Rafalswierczek"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid7Symfony"
php -d memory_limit=32000M vendor/bin/phpunit --filter "testCreate50MUuid7Ramsey"

```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance67

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~148 days

Recently: every ~247 days

Total

9

Last Release

191d ago

Major Versions

1.3.3 → 2.02025-10-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/25b0d337f0f34a08f6adcf9603a9f4f942326d7794bdc9287a320a3284e10f10?d=identicon)[rafalswierczek](/maintainers/rafalswierczek)

---

Top Contributors

[![rafalswierczek](https://avatars.githubusercontent.com/u/37018158?v=4)](https://github.com/rafalswierczek "rafalswierczek (20 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[mbissonho/module-remember-admin-last-page

This module allow a admin user to come back to the same page(order, customer or config management) when it's session expires.

102.1k](/packages/mbissonho-module-remember-admin-last-page)

PHPackages © 2026

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