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

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

ordinary/uid
============

Library for using and generating universally unique ids.

1.0.0(3y ago)39MITPHPPHP ^8.2

Since Feb 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/brandonja991/ordinary-uid)[ Packagist](https://packagist.org/packages/ordinary/uid)[ RSS](/packages/ordinary-uid/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (11)Versions (2)Used By (0)

Ordinary UID
============

[](#ordinary-uid)

Ordinary UID is a simple solution for generating universally unique ids.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
- [UID Interface](#uid-interface-methods)
    - [`UIDInterface::value()`](#uidinterfacevalue)
    - [`UIDInterface::dateTime()`](#uidinterfacedatetime)
    - [`UIDInterface::timeSeconds()`](#uidinterfacetimeseconds)
    - [`UIDInterface::timeFraction()`](#uidinterfacetimefraction)
    - [`UIDInterface::timePrecision()`](#uidinterfacetimeprecision)
    - [`UIDInterface::custom()`](#uidinterfacecustom)
- [UID Generator](#uid-generator-methods)
    - [`Generator::generate(int $customBytes)`](#generatorgenerateint-custombytes)
    - [`Generator::generateCustom(string $custom)`](#generatorgeneratecustomstring-custom)

Getting Started
---------------

[](#getting-started)

Install using composer.

```
composer require ordinary/uid
```

Using the generator

```
require_once 'vendor/autoload.php';

$randomizer = new \Random\Randomizer(new \Random\Engine\Secure());
$clock = new \Ordinary\Clock\UTCClock();
$generator = new \Ordinary\UID\Generator($clock, $randomizer);

var_dump($generator->generate(4));
var_dump($generator->generateCustom('external-id-1'))
```

Features
--------

[](#features)

### Universally unique

[](#universally-unique)

IDs generated are considered to be universally unique with the assumption that no two machines will generate a UID at the exact same time with the exact same random bytes.

### Time based

[](#time-based)

The first part is a hexadecimal representation of the timestamp from which it was created. The second part is also a hexadecimal representation of the fractional time of the timestamp from which it was created

### Sortable

[](#sortable)

With the first two parts being representations of time, UIDs can be easily sorted by creation time, by sorting them by their string value. Additionally, if UID is generated using a custom value for custom bytes, the custom bytes portion will be sortable as well, as long as the custom value would have been sortable.

### Custom time precision

[](#custom-time-precision)

- Time precision can be customized to use millisecond, microsecond, or nanosecond granularity.
- Microsecond granularity is default (1,000,000 UIDs per second)

### Custom unique identifiers

[](#custom-unique-identifiers)

The last part contains bytes converted to a hexadecimal (Max: 15). This can be used to add a custom identifier, or to add additional uniqueness to the ID.

UID Interface Methods
---------------------

[](#uid-interface-methods)

### `UIDInterface::value()`

[](#uidinterfacevalue)

Get the string value of a UID instance.

### `UIDInterface::dateTime()`

[](#uidinterfacedatetime)

Get a DateTimeImmutable instance of the UID.

### `UIDInterface::timeSeconds()`

[](#uidinterfacetimeseconds)

Get the timestamp in seconds of the UID.

### `UIDInterface::timeFraction()`

[](#uidinterfacetimefraction)

Get the fraction of a second in units determined by the precision.

### `UIDInterface::timePrecision()`

[](#uidinterfacetimeprecision)

Get the precision used to create the UID.

### `UIDInterface::custom()`

[](#uidinterfacecustom)

Get the custom bytes of the UID.

UID Generator Methods
---------------------

[](#uid-generator-methods)

### `Generator::generate(int $customBytes)`

[](#generatorgenerateint-custombytes)

Generate an Ordinary UID with a given number of random bytes.

### `Generator::generateCustom(string $custom)`

[](#generatorgeneratecustomstring-custom)

Generate an Ordinary UID with the given bytes. `$custom` can be any string as long as the number of bytes is between 1 and 15.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

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

Unknown

Total

1

Last Release

1240d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/67129137?v=4)[brandonja](/maintainers/brandonja)[@brandonja](https://github.com/brandonja)

---

Top Contributors

[![brandonja991](https://avatars.githubusercontent.com/u/95324323?v=4)](https://github.com/brandonja991 "brandonja991 (58 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k51](/packages/ecotone-ecotone)[symfony/clock

Decouples applications from the system clock

436205.7M389](/packages/symfony-clock)[lcobucci/clock

Yet another clock abstraction

800207.5M163](/packages/lcobucci-clock)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k103](/packages/flow-php-etl)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M86](/packages/mcp-sdk)

PHPackages © 2026

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