PHPackages                             infocyph/uid - 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. infocyph/uid

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

infocyph/uid
============

UUID (RFC 4122 + Unofficial/Draft), ULID, Snowflake ID, Sonyflake ID, TBSL (library exclusive) generator!

3.0.2(5mo ago)105.1k↓50%MITPHPPHP &gt;=8.0CI passing

Since Apr 22Pushed 5mo ago1 watchersCompare

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

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

UID
===

[](#uid)

[![build](https://github.com/infocyph/UID/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/infocyph/UID/actions/workflows/build.yml)[![Codacy Badge](https://camo.githubusercontent.com/5f208936440af447ff93a62e56308929078dcff296e89349be130b8ac788ef53/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6365633463376564306532373462336461343537313937333733326133363365)](https://app.codacy.com/gh/infocyph/UID/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![Packagist Downloads](https://camo.githubusercontent.com/a4e7a4f94178664a259647de3fa768eb3a45b503024b51bcf3611fb7e2048dab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e666f637970682f756964)](https://camo.githubusercontent.com/a4e7a4f94178664a259647de3fa768eb3a45b503024b51bcf3611fb7e2048dab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e666f637970682f756964)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![Packagist Version](https://camo.githubusercontent.com/ec6b885ac18c098a38950f91510cf7480a78177f578c68b159fe6f3229066882/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e666f637970682f756964)](https://camo.githubusercontent.com/ec6b885ac18c098a38950f91510cf7480a78177f578c68b159fe6f3229066882/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e666f637970682f756964)[![Packagist PHP Version Support](https://camo.githubusercontent.com/a032bb75a70aebf4f6dc1c2bab471f310d75f89f2d1fc61823c70b986cfbbfaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e666f637970682f756964)](https://camo.githubusercontent.com/a032bb75a70aebf4f6dc1c2bab471f310d75f89f2d1fc61823c70b986cfbbfaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e666f637970682f756964)[![GitHub code size in bytes](https://camo.githubusercontent.com/2ce0b124dc235b424cf4058af40af257ec1d2715964f26d480270302c803fd87/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f696e666f637970682f756964)](https://camo.githubusercontent.com/2ce0b124dc235b424cf4058af40af257ec1d2715964f26d480270302c803fd87/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f696e666f637970682f756964)[![]()](https://visitor-badge.laobi.icu/badge?page_id=infocyph.com)

An AIO Unique ID generator written in PHP. Supports (references available at the bottom),

- UUID
- ULID
- Snowflake ID
- Sonyflake ID
- TBSL
- NanoId
- Cuid2

Table of contents
-----------------

[](#table-of-contents)

- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
    - [UUID](#uuid-universal-unique-identifier)
        - [UUID v1](#uuid-v1-time-based-uuid)
        - [UUID v3](#uuid-v3-namespace-based-uuid)
        - [UUID v4](#uuid-v4-random-uuid)
        - [UUID v5](#uuid-v5-namespace-based-uuid)
        - [UUID v6](#uuid-v6-draft-basedunofficial-time-based-uuid)
        - [UUID v7](#uuid-v7-draft-basedunofficial-time-based-uuid)
        - [UUID v8](#uuid-v8-draft-basedunofficial-time-based-uuid-lexicographically-sortable)
        - [GUID](#guid)
        - [Additional](#additional)
    - [ULID](#ulid-universally-unique-lexicographically-sortable-identifier)
    - [Snowflake ID](#snowflake-id)
    - [Sonyflake ID](#sonyflake-id)
    - [TBSL ID](#tbsl-time-based-keys-with-lexicographic-sorting-library-exclusive)
    - [RandomId](#randomid)
        - [NanoId](#nanoid-url-friendly-unique-random-id)
        - [Cuid2](#cuid2-url-friendly-secure--collision-free)
- [Benchmark](#benchmark)
- [Support](#support)
- [References](#references)

Prerequisites
-------------

[](#prerequisites)

Language: PHP 8/+

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

[](#installation)

```
composer require infocyph/uid

```

Usage
-----

[](#usage)

### UUID (Universal Unique Identifier)

[](#uuid-universal-unique-identifier)

The node specific UUID's `$node` parameter (1, 6, 7, 8) is optional. If not provided, it will be generated randomly. But, if you wanna track the source of the UUIDs, you should use it (pre-define the node per server &amp; pass it accordingly).

#### UUID v1: Time-based UUID.

[](#uuid-v1-time-based-uuid)

- Generate v1 UUID

```
// Get v1 UUID
\Infocyph\UID\UUID::v1();
// alternatively can also use
uuid1();
```

- Pass your pre-generated node (for node specific UUID)

```
\Infocyph\UID\UUID::v1($node); // check additional section for how to generate one
```

#### UUID v3: Namespace based UUID.

[](#uuid-v3-namespace-based-uuid)

- Generate v3 UUID

```
// Get v3 UUID
\Infocyph\UID\UUID::v3('a pre-generated UUID', 'the string you wanna get UUID for');
// alternatively can also use
uuid3();
```

- Get v3 UUID for predefined namespaces (RFC4122 #Appendix C)

```
/**
* You can pass X500, URL, OID, DNS (check RFC4122 #Appendix C)
*/
\Infocyph\UID\UUID::v3('url', 'abmmhasan.github.io');
```

- You can generate a UUID &amp; use as namespace as well

```
\Infocyph\UID\UUID::v3('fa1700dd-828c-4d1b-8e6d-a6104807da90', 'abmmhasan.github.io');
```

#### UUID v4: Random UUID.

[](#uuid-v4-random-uuid)

- Generate v4 UUID

```
// Get v4 UUID (completely random)
\Infocyph\UID\UUID::v4();
// alternatively can also use
uuid4();
```

#### UUID v5: Namespace based UUID.

[](#uuid-v5-namespace-based-uuid)

- Generate v5 UUID

```
// Get v5 UUID
\Infocyph\UID\UUID::v5('a pre-generated UUID', 'the string you wanna get UUID for');
// alternatively can also use
uuid5();
```

- Get v5 UUID for predefined namespaces (RFC4122 #Appendix C)

```
/**
* You can pass X500, URL, OID, DNS (check RFC4122 #Appendix C)
*/
\Infocyph\UID\UUID::v5('url', 'abmmhasan.github.io');
```

- You can generate a UUID &amp; use as namespace as well

```
UUID::v5('fa1700dd-828c-4d1b-8e6d-a6104807da90', 'abmmhasan.github.io');
```

#### UUID v6 (draft-based/unofficial): Time-based UUID.

[](#uuid-v6-draft-basedunofficial-time-based-uuid)

- Generate v6 UUID

```
// Get v6 UUID (Time based)
\Infocyph\UID\UUID::v6();
// alternatively can also use
uuid6();
```

- Get v6 UUID using predefined node:

```
\Infocyph\UID\UUID::v6($node); // check additional section for how to generate one
```

#### UUID v7 (draft-based/unofficial): Time-based UUID.

[](#uuid-v7-draft-basedunofficial-time-based-uuid)

- Generate v7 UUID

```
// Get v7 UUID for current time
\Infocyph\UID\UUID::v7();
// alternatively can also use
uuid7();
```

- Get v7 UUID using predefined node:

```
\Infocyph\UID\UUID::v7(null, $node); // check additional section for, how to generate one
```

- Or if you wanna get v7 UUID using predefined time:

```
$timeInterface = new DateTime(); // DateTime implements DateTimeInterface
\Infocyph\UID\UUID::v7($timeInterface);
```

- You can combine both parameters together as well.

#### UUID v8 (draft-based/unofficial): Time-based UUID. Lexicographically sortable.

[](#uuid-v8-draft-basedunofficial-time-based-uuid-lexicographically-sortable)

- Generate v8 UUID

```
// Get v8 UUID
\Infocyph\UID\UUID::v8();
// alternatively can also use
uuid8();
```

- Get v8 UUID using predefined node:

```
\Infocyph\UID\UUID::v8($node); // check additional section for, how to generate one
```

#### GUID

[](#guid)

GUID generator, works in all platform. Generate:

```
\Infocyph\UID\UUID::guid()
```

*Note: Sending false in only parameter will return the string enclosed with Braces*

#### Additional

[](#additional)

- Generate node for further use (with version: 1, 6, 7, 8)

```
\Infocyph\UID\UUID::getNode();
```

- Parse any UUID string:

```
\Infocyph\UID\UUID::parse($uuid); // returns ['isValid', 'version', 'time', 'node']
```

### ULID (Universally Unique Lexicographically Sortable Identifier)

[](#ulid-universally-unique-lexicographically-sortable-identifier)

- Generating ULID is very simple,

```
\Infocyph\UID\ULID::generate();
```

- Or if you wanna get ULID for specific time:

```
\Infocyph\UID\ULID::generate(new DateTimeImmutable('2020-01-01 00:00:00'));
```

- Extract datetime from any ULID string:

```
\Infocyph\UID\ULID::getTime($ulid); // returns DateTimeInterface object
```

- Validate any ULID string:

```
\Infocyph\UID\ULID::isValid($ulid); // true/false
```

### Snowflake ID

[](#snowflake-id)

- Generate a new Snowflake ID (You can also pass your pre-generated worker\_id &amp; datacenter\_id for server/module detection):

```
// Get Snowflake ID
// optionally you can set worker_id & datacenter_id, for server/module detection
\Infocyph\UID\Snowflake::generate();
// alternatively
snowflake();
```

- Parse Snowflake ID (get the timestamp, sequence, worker\_id, datacenter\_id):

```
// Parse Snowflake ID
// returns [time => DateTimeInterface object, sequence, worker_id, datacenter_id]
\Infocyph\UID\Snowflake::parse($snowflake);
```

- Specify start time for Snowflake ID (a Snowflake ID is unique upto 69 years from the start date):

```
// By default, the start time is set to `2020-01-01 00:00:00`, which is changeable
// but if changed, this should always stay same as long as your project lives
// & must call this before any Snowflake call (generate/parse)
\Infocyph\UID\Snowflake::setStartTimeStamp('2000-01-01 00:00:00');
```

### Sonyflake ID

[](#sonyflake-id)

- Generate a new Sonyflake ID (You can also pass your pre-generated machine\_id for server detection):

```
// Get Sonyflake ID
// optionally set machine_id, for server detection
\Infocyph\UID\Sonyflake::generate();
// alternatively
\Infocyph\UID\sonyflake();
```

- Parse Sonyflake ID (get the timestamp, sequence, machine\_id):

```
// Parse Sonyflake ID
// returns [time => DateTimeInterface object, sequence, machine_id]
\Infocyph\UID\Sonyflake::parse($sonyflake);
```

- Specify start time for Sonyflake ID (a Sonyflake ID is unique upto 174 years from the start date):

```
// By default, the start time is set to `2020-01-01 00:00:00`, which is changeable
// but if changed, this should always stay same as long as your project lives
// & must call this before any Sonyflake call (generate/parse)
\Infocyph\UID\Sonyflake::setStartTimeStamp('2000-01-01 00:00:00');
```

### TBSL: Time-Based Keys with Lexicographic Sorting (library exclusive)

[](#tbsl-time-based-keys-with-lexicographic-sorting-library-exclusive)

- Get TBSL ID (You can also pass your pre-generated machine\_id for server detection):

```
// Get TBSL ID
// optionally set machine_id, for server detection
\Infocyph\UID\TBSL::generate();
// alternatively
tbsl();
```

- Parse TBSL ID (get the timestamp, machine\_id):

```
// Parse TBSL
// returns [isValid, time => DateTimeInterface object, machine_id]
\Infocyph\UID\TBSL::parse($tbsl);
```

- Getting unique sequence

```
tbsl(0, true); // send true in 2nd parameter to enable sequence
```

### RandomId

[](#randomid)

With this you can generate RandomIds. These are great for usage where you don't want a large length/formatted IDs like UUID4. These IDs are unique &amp; can't be backtracked.

#### NanoID (URL friendly Unique Random ID)

[](#nanoid-url-friendly-unique-random-id)

- Generate

```
// By default, it will generate id of length 21.
// You can pass in desired length
\Infocyph\UID\RandomId::nanoId();
```

#### Cuid2 (URL friendly, secure &amp; collision free)

[](#cuid2-url-friendly-secure--collision-free)

- Generate

```
// By default, it will generate id of length 24.
// You can pass in desired length in between 4 & 24
\Infocyph\UID\RandomId::cuid2();
```

Benchmark
---------

[](#benchmark)

TypeGeneration time (ms)UUID v1 (random node)0.00411 (ramsey/Uuid: 0.18753)UUID v1 (fixed node)0.00115 (ramsey/Uuid: 0.17386)UUID v3 (custom namespace)0.00257 (ramsey/Uuid: 0.03015)UUID v40.00362 (ramsey/Uuid: 0.16501)UUID v5 (custom namespace)0.00108 (ramsey/Uuid: 0.03658)UUID v6 (random node)0.00444 (ramsey/Uuid: 0.17469)UUID v6 (fixed node)0.00164 (ramsey/Uuid: 0.17382)UUID v7 (random node)0.00503 (ramsey/Uuid: 0.16278)UUID v7 (fixed node)0.00154 (ramsey/Uuid: 0.18753)UUID v8 (random node)0.00505 (ramsey/Uuid: N/A)UUID v8 (fixed node)0.00209 (ramsey/Uuid: 0.16029 *\*predefined random node, not usable as signature*)ULID0.00506 (robinvdvleuten/php-ulid: 0.00508)Snowflake0.13951 (godruoyi/php-snowflake: 0.14856)Sonyflake0.13821 (godruoyi/php-snowflake: 0.14583)TBSL0.0034NanoID0.00057Cuid20.01817Support
-------

[](#support)

Having trouble? Create an issue!

References
----------

[](#references)

- UUID (RFC4122):
- UUID (Drafts/Proposals):
- ULID:
- Snowflake ID:
- Sonyflake ID:
- TBSL ID:
- NanoID:
- Cuid2:

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance73

Regular maintenance activity

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Recently: every ~139 days

Total

18

Last Release

152d ago

Major Versions

0.01 → 1.02024-04-25

1.03.1 → 2.02024-05-03

2.03 → 3.02025-03-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/33b750b84ab22f2038ef9b90ee48f2fcdaab6b5698e9f956a89a152466200b63?d=identicon)[abmmhasan](/maintainers/abmmhasan)

---

Top Contributors

[![abmmhasan](https://avatars.githubusercontent.com/u/7711128?v=4)](https://github.com/abmmhasan "abmmhasan (78 commits)")

---

Tags

cuid2guididentifiernanoidphpphp-libraryphp8snowflakesonyflaketbsluidulidunique-identifieruuiduuidulidkeyiduniquerfc4122sonyflakesnowflaketbsl

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/infocyph-uid/health.svg)

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

###  Alternatives

[symfony/uid

Provides an object-oriented API to generate and represent UIDs

610280.0M754](/packages/symfony-uid)[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.3M129](/packages/webpatser-laravel-uuid)[identifier/identifier

Common Interfaces and Factories for Identifiers

3226.2k1](/packages/identifier-identifier)[ramsey/identifier

A PHP library for generating and working with identifiers, including UUIDs, ULIDs, and Snowflakes

603.0k1](/packages/ramsey-identifier)[pugx/shortid-php

An implementation of shortid in PHP

52588.5k3](/packages/pugx-shortid-php)[michalsn/codeigniter4-uuid

UUID and ULID package for CodeIgniter 4 with support for Model.

4728.7k4](/packages/michalsn-codeigniter4-uuid)

PHPackages © 2026

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