PHPackages                             universetech-inc/xid-php - 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. universetech-inc/xid-php

ActiveLibrary

universetech-inc/xid-php
========================

Globally Unique ID Generator

1.0.1(3y ago)1116.6k↓37.5%1MITPHPPHP &gt;=7.0.0

Since Jun 27Pushed 3y ago3 watchersCompare

[ Source](https://github.com/universetech-inc/xid-php)[ Packagist](https://packagist.org/packages/universetech-inc/xid-php)[ Docs](https://github.com/fpay/xid-php)[ RSS](/packages/universetech-inc-xid-php/feed)WikiDiscussions main Synced 1mo ago

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

Globally Unique ID Generator
============================

[](#globally-unique-id-generator)

[![Latest Stable Version](https://camo.githubusercontent.com/0dd78e8e1e38a1a0394582163f05172cc1a3f55efff723335016db75b282d62e/68747470733a2f2f706f7365722e707567782e6f72672f667061792f7869642d7068702f762f737461626c65)](https://packagist.org/packages/fpay/xid-php)[![Total Downloads](https://camo.githubusercontent.com/7dd20d3a855301598a3c8da548ea3a6a5550454efc7fc1a9a01fc01a4b2deb0d/68747470733a2f2f706f7365722e707567782e6f72672f667061792f7869642d7068702f646f776e6c6f616473)](https://packagist.org/packages/fpay/xid-php)[![Latest Unstable Version](https://camo.githubusercontent.com/e04dd8e81c903f17b0c51f02d9b2af0cb4be42271bdac91fc7320f990b73a64f/68747470733a2f2f706f7365722e707567782e6f72672f667061792f7869642d7068702f762f756e737461626c65)](https://packagist.org/packages/fpay/xid-php)[![License](https://camo.githubusercontent.com/4b246ddfc6b820d96c8de598fb9f6fe8152558c91e7b9dc4212afac0405ad2a6/68747470733a2f2f706f7365722e707567782e6f72672f667061792f7869642d7068702f6c6963656e7365)](https://packagist.org/packages/fpay/xid-php)[![Build Status](https://camo.githubusercontent.com/7ab0995b6fc72170bea4d07391e714c9fa3db3409aecc21bd40e29e70e0c5e38/68747470733a2f2f7472617669732d63692e6f72672f667061792f7869642d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/fpay/xid-php)[![codecov](https://camo.githubusercontent.com/7a5200e55376776e84e312122cdfd1c9bf8989812ce95f72189b0e991e3794c6/68747470733a2f2f636f6465636f762e696f2f67682f667061792f7869642d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/fpay/xid-php)

> This project is a PHP implementation of the Go Lang library found here:

Package xid is a globally unique id generator library, ready to be used safely directly in your server code.

Xid is using Mongo Object ID algorithm to generate globally unique ids with a different serialization (base64) to make it shorter when transported as a string:

- 4-byte value representing the seconds since the Unix epoch,
- 3-byte machine identifier,
- 2-byte process id, and
- 3-byte counter, starting with a random value.

The binary representation of the id is compatible with Mongo 12 bytes Object IDs. The string representation is using base32 hex (w/o padding) for better space efficiency when stored in that form (20 bytes). The hex variant of base32 is used to retain the sortable property of the id.

Xid doesn't use base64 because case sensitivity and the 2 non alphanum chars may be an issue when transported as a string between various systems. Base36 wasn't retained either because 1/ it's not standard 2/ the resulting size is not predictable (not bit aligned) and 3/ it would not remain sortable. To validate a base32 `xid`, expect a 20 chars long, all lowercase sequence of `a` to `v` letters and `0` to `9` numbers (`[0-9a-v]{20}`).

UUIDs are 16 bytes (128 bits) and 36 chars as string representation. Twitter Snowflake ids are 8 bytes (64 bits) but require machine/data-center configuration and/or central generator servers. xid stands in between with 12 bytes (96 bits) and a more compact URL-safe string representation (20 chars). No configuration or central generator server is required so it can be used directly in server's code.

NameBinary SizeString SizeFeatures[UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier)16 bytes36 charsconfiguration free, not sortable[shortuuid](https://github.com/stochastic-technologies/shortuuid)16 bytes22 charsconfiguration free, not sortable[Snowflake](https://blog.twitter.com/2010/announcing-snowflake)8 bytesup to 20 charsneeds machin/DC configuration, needs central server, sortable[MongoID](https://docs.mongodb.org/manual/reference/object-id/)12 bytes24 charsconfiguration free, sortablexid12 bytes20 charsconfiguration free, sortableFeatures:

- Size: 12 bytes (96 bits), smaller than UUID, larger than snowflake
- Base32 hex encoded by default (20 chars when transported as printable string, still sortable)
- Non configured, you don't need set a unique machine and/or data center id
- K-ordered
- Embedded time with 1 second precision
- Unicity guaranteed for 16,777,216 (24 bits) unique ids per second and per host/process

Best used with [xlog](https://github.com/rs/xlog)'s [RequestIDHandler](https://godoc.org/github.com/rs/xlog#RequestIDHandler).

References:

-
- [https://en.wikipedia.org/wiki/Universally\_unique\_identifier](https://en.wikipedia.org/wiki/Universally_unique_identifier)
-
- Python port by [Graham Abbott](https://github.com/graham): [https://github.com/graham/python\_xid](https://github.com/graham/python_xid)

Install
-------

[](#install)

Requirements:

1. PHP &gt;= 7.0.0
2. POSIX enabled
3. APCu extension (optional, to share counter across requests)

```
composer require fpay/xid-php
```

Usage
-----

[](#usage)

```
$guid = \Fpay\Xid\Generator::create();

echo $guid . PHP_EOL;
// Output: 9m4e2mr0ui3e8a215n4g
```

Get `xid` embedded info:

```
$guid->machine();
$guid->pid();
$guid->time();
$guid->counter();
```

Decode from string:

```
$guid = \Fpay\Xid\Generator::fromString("9m4e2mr0ui3e8a215n4g");
```

Licenses
--------

[](#licenses)

All source code is licensed under the [MIT License](https://raw.github.com/fpay/xid-php/master/LICENSE).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

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

1422d ago

### Community

Maintainers

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

---

Top Contributors

[![albertcht](https://avatars.githubusercontent.com/u/9117929?v=4)](https://github.com/albertcht "albertcht (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/universetech-inc-xid-php/health.svg)

```
[![Health](https://phpackages.com/badges/universetech-inc-xid-php/health.svg)](https://phpackages.com/packages/universetech-inc-xid-php)
```

PHPackages © 2026

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