PHPackages                             linkorb/xuid - 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. linkorb/xuid

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

linkorb/xuid
============

XUID library for PHP

v1.5.0(3mo ago)518.8k↑146.2%2[1 PRs](https://github.com/linkorb/xuid/pulls)2MITPHPCI passing

Since Dec 13Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/linkorb/xuid)[ Packagist](https://packagist.org/packages/linkorb/xuid)[ Docs](https://github.com/linkorb/xuid)[ RSS](/packages/linkorb-xuid/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (4)Versions (12)Used By (2)

XUID Library
============

[](#xuid-library)

XUIDs are URL-friendly compressed UUIDs [www.xuid.org](http://www.xuid.org)

Why XUIDs?
----------

[](#why-xuids)

A UUID v4 is a great choice as a primary key for your database tables.

But, they are quite long to use in URLs and databases : 32 alphanumeric characters and four hyphens (36 characters total)

A XUID is a UUID, converted into a 128-bit value, converted into a base64 string (stripped from padding characters), then converted into url-safe base64 (replacing `+` and `/` into `-` and `_` respectively - custom mappings available, see below for more info).

This gives you a 22 character string, safe to use in URLs.

It also safely decodes into a full UUID string again.

Benefits
--------

[](#benefits)

- Takes less space in database fields
- Shorter URLs
- Un-guessable primary keys in URLs

Usage
-----

[](#usage)

```
use Xuid\Xuid;

$xuid = new Xuid();

$in = $xuid->getUuid(); // ffe25f31-907e-46c0-b2f8-8bbfedb9082b

$tmp = $xuid->encode($in); // _-JfMZB-RsCy-Iu_7bkIKw

$out = $xuid->decode($tmp); // ffe25f31-907e-46c0-b2f8-8bbfedb9082b

$tmp = $xuid->getXuid();

$newXuid = $xuid->getXuid();
if (!$xuid->isValidXuid($newXuid)) {
    // this Xuid is valid
}
```

All methods can be called statically as well:

```
use Xuid\Xuid;

$x = Xuid::getXuid();
$u = Xuid::decode($x);
```

Example
-------

[](#example)

You'll find example code in the `example/` directory.

To generate 100 XUIDs, run the following command:

```
php example/generate.php

```

Example output:

```
y9G-jWmYQcW5HyxiU_Pnew: cbd1be8d-6998-41c5-b91f-2c6253f3e77b
IOnEowPFR-G74hEBtTSJVQ: 20e9c4a3-03c5-47e1-bbe2-1101b5348955
Jgn4-Hs3STyNMC_ectX4kA: 2609f8f8-7b37-493c-8d30-2fde72d5f890
-rO6xKQFQCGPozxJf35lGw: fab3bac4-a405-4021-8fa3-3c497f7e651b
c6l3fR3mThSlL1OlNYgCvg: 73a9777d-1de6-4e14-a52f-53a5358802be
3PK9eo00T92z6oSsFNCY-A: dcf2bd7a-8d34-4fdd-b3ea-84ac14d098f8
vCMyGdkGT-m6e6m4BKcfgA: bc233219-d906-4fe9-ba7b-a9b804a71f80
JJ_1Ndd3S9SwG9urLr5NTQ: 249ff535-d777-4bd4-b01b-dbab2ebe4d4d
KSn-sn-cToydyfvjLZHhBA: 2929feb2-7f9c-4e8c-9dc9-fbe32d91e104
fi_nfoXrQ_GoYrzT4oZqRw: 7e2fe77e-85eb-43f1-a862-bcd3e2866a47
1vKKRSlHQICMj5X5iktHZA: d6f28a45-2947-4080-8c8f-95f98a4b4764
yWJ5VPsISbS46anoEO2HVQ: c9627954-fb08-49b4-b8e9-a9e810ed8755
...etc

```

Generatic alpha-numeric XUIDs only
----------------------------------

[](#generatic-alpha-numeric-xuids-only)

`-` and `_` are occassionally found in XUIDs. If you prefer alpha-numeric only XUIDs, simply call the following static method before generating your XUIDs:

```
Xuid\Xuid::alphaNumericOnly();
```

This will keep generating XUIDs until one is found that only contains alphanumeric characters. That means that it could require two or more attempts before a valid XUID can be returned. In practice this does not add any noticable latency. But this is worth keeping in mind when generating XUIDs in bulk.

Custom character mappings
-------------------------

[](#custom-character-mappings)

The default character mapping for XUIDs (url safe) is:

- `+` =&gt; `-`
- `/` =&gt; `_`

But you can apply any other mapping you want for any of the characters used in base64 encoding, by calling `Xuid::map()`. For example, you can create double-click safe XUIDs (the whole XUID is selectable simply by double clicking it), by mapping `+` and `_` to selectable characters. For example:

```
Xuid::setMap(
    [
        '+' => 'Æ',
        '/' => 'Ä',
    ]
);

echo Xuid::getXuid() . PHP_EOL; // Outputs a XUID such as `xQamÆ0kGSjepUAD1bÄ09kg`
```

Beware to only pass in URL safe characters if your use-case requires URL safe XUIDs.

PHPUnit tests
-------------

[](#phpunit-tests)

```
vendor/bin/phpunit test/

```

Brought to you by the LinkORB Engineering team
----------------------------------------------

[](#brought-to-you-by-the-linkorb-engineering-team)

[![](https://camo.githubusercontent.com/62fb66b034de7ea7fca9fd9776424b5348daa76ef8622caf92c2f7622003e5ef/687474703a2f2f7777772e6c696e6b6f72622e636f6d2f642f6d6574612f74696572312f696d616765732f6c696e6b6f7262656e67696e656572696e672d6c6f676f2e706e67)](https://camo.githubusercontent.com/62fb66b034de7ea7fca9fd9776424b5348daa76ef8622caf92c2f7622003e5ef/687474703a2f2f7777772e6c696e6b6f72622e636f6d2f642f6d6574612f74696572312f696d616765732f6c696e6b6f7262656e67696e656572696e672d6c6f676f2e706e67)
Check out our other projects at [engineering.linkorb.com](http://engineering.linkorb.com).

Btw, we're hiring!

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance83

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 82.4% 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 ~537 days

Recently: every ~634 days

Total

8

Last Release

95d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1db66b320db18b8036ea68211b7d8a39e7c6da97e6fd29f59a50380ebb69d0bb?d=identicon)[joostfaassen](/maintainers/joostfaassen)

![](https://www.gravatar.com/avatar/19f8d602132a01fd1e79793c91e73aed64ea31f65748096e4120904169027779?d=identicon)[boite](/maintainers/boite)

---

Top Contributors

[![joostfaassen](https://avatars.githubusercontent.com/u/411113?v=4)](https://github.com/joostfaassen "joostfaassen (14 commits)")[![h-wang](https://avatars.githubusercontent.com/u/3410322?v=4)](https://github.com/h-wang "h-wang (1 commits)")[![prajapati-kaushik](https://avatars.githubusercontent.com/u/10140681?v=4)](https://github.com/prajapati-kaushik "prajapati-kaushik (1 commits)")[![yormy](https://avatars.githubusercontent.com/u/37929978?v=4)](https://github.com/yormy "yormy (1 commits)")

---

Tags

xuid

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/linkorb-xuid/health.svg)

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

###  Alternatives

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k78.3k91](/packages/pocketmine-pocketmine-mp)[mynaparrot/plugnmeet-sdk

plugNmeet PHP SDK

102.8k](/packages/mynaparrot-plugnmeet-sdk)

PHPackages © 2026

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