PHPackages                             castor/identifier - 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. castor/identifier

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

castor/identifier
=================

High-performance 128-bit identifier extension for PHP (UUIDs and ULIDs)

v0.2.1(6mo ago)65[3 issues](https://github.com/castor-labs/php-ext-identifier/issues)MITCPHP ^8.1CI passing

Since Nov 16Pushed 6mo agoCompare

[ Source](https://github.com/castor-labs/php-ext-identifier)[ Packagist](https://packagist.org/packages/castor/identifier)[ RSS](/packages/castor-identifier/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Extension Identifier
====================

[](#extension-identifier)

A high-performance PHP extension for working with 128-bit identifiers including UUIDs and ULIDs.

Features
--------

[](#features)

- **128-bit Base Class**: `Identifier\Bit128` for all 128-bit identifiers
- **Complete UUID Support**: All UUID versions (1, 3, 4, 5, 6, 7) with proper RFC compliance
- **ULID Support**: Universally Unique Lexicographically Sortable Identifiers with monotonic ordering
- **Thread Safety**: Full thread safety for ULID monotonic generation using TSRM (Thread Safe Resource Manager)
- **Context System**: Deterministic generation for testing with `FixedContext`
- **Exceptional Performance**: Native C implementation delivering 9.9M+ ULID ops/sec, 2.8M+ UUID ops/sec
- **Type Safety**: Proper PHP class hierarchy with inheritance

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

[](#installation)

### Requirements

[](#requirements)

- PHP 8.1 or higher
- Zig 0.15.2+ ([Download from ziglang.org](https://ziglang.org/download/)) - *The amazing build system that makes this all possible*

### Build and Install

[](#build-and-install)

```
git clone https://github.com/your-org/php-ext-identifier.git
cd php-ext-identifier
zig build dev  # Build + test in one command
```

For production installation:

```
zig build install-system  # Install to system PHP (requires sudo)
```

### Enable Extension

[](#enable-extension)

Add to your `php.ini`:

```
extension=identifier
```

Quick Start
-----------

[](#quick-start)

```
use Identifier\Uuid\Version4;
use Identifier\Uuid\Version7;
use Identifier\Ulid;

// Generate random UUID v4
$uuid = Version4::generate();
echo $uuid->toString(); // e.g., "550e8400-e29b-41d4-a716-446655440000"

// Generate timestamp-based UUID v7
$uuid7 = Version7::generate();
echo $uuid7->toString();

// Generate ULID
$ulid = Ulid::generate();
echo $ulid->toString(); // e.g., "01ARZ3NDEKTSV4RRFFQ69G5FAV"
```

Testing with Fixed Context
--------------------------

[](#testing-with-fixed-context)

```
use Identifier\Context\Fixed;
use Identifier\Uuid\Version4;

// Create deterministic context for testing
$ctx = Fixed::create(1640995200000, 12345);

// Generate deterministic UUIDs
$uuid1 = Version4::generate($ctx);
$uuid7 = Version7::generate($ctx);
$ulid = Ulid::generate($ctx);

// Both calls with same context will produce same results
```

Thread Safety
-------------

[](#thread-safety)

This extension is **fully thread-safe** for ULID monotonic generation in multi-threaded PHP environments (ZTS builds). The implementation uses PHP's TSRM (Thread Safe Resource Manager) to ensure proper thread isolation.

### How Thread Safety Works

[](#how-thread-safety-works)

- **Thread Isolation**: Each thread maintains its own monotonic state (last timestamp and randomness)
- **Zero Contention**: No locks or synchronization required - each thread operates independently
- **Monotonic Ordering**: ULIDs generated within a single thread are guaranteed to be monotonically increasing
- **Performance**: Thread safety comes with zero performance overhead

### Compatibility

[](#compatibility)

- ✅ **Apache mod\_php** (both threaded and non-threaded)
- ✅ **Apache mod\_worker** (requires ZTS PHP build)
- ✅ **Windows IIS** (requires ZTS PHP build)
- ✅ **PHP-FPM** (process-based, inherently thread-safe)
- ✅ **CLI** (single-threaded by default)

### Build Considerations

[](#build-considerations)

The same extension binary works for both ZTS (thread-safe) and non-ZTS PHP builds:

```
# Check if your PHP build supports threading
php -m | grep -i zts
php-config --configure-options | grep -i zts
```

For web servers that use threading (like Apache mod\_worker or IIS), ensure you're using a ZTS PHP build to get full thread safety benefits.

API Documentation
-----------------

[](#api-documentation)

Check the [stub file](stubs/identifier.stub.php) for a detailed API documentation.

Testing
-------

[](#testing)

```
zig build test      # Run all tests
zig build dev       # Build + test
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure all tests pass (`zig build test`)
5. Submit a pull request

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Acknowledgments
---------------

[](#acknowledgments)

- **[Zig Programming Language](https://ziglang.org/)** - This project is built using Zig's incredible embedded C compiler and build system. Zig's seamless C interop, cross-compilation capabilities, and modern build tooling make it the perfect choice for PHP extension development. Special thanks to the Zig team for creating such an outstanding development experience.
- [RFC 4122](https://tools.ietf.org/html/rfc4122) - UUID specification
- [RFC 9562](https://tools.ietf.org/html/rfc9562) - Updated UUID specification
- [ULID Specification](https://github.com/ulid/spec) - ULID format specification

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance59

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 60% 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 ~0 days

Total

2

Last Release

183d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79e7625b4370021decec6b5b24191d657cf1f0435181bc26791314317e71155a?d=identicon)[mnavarrocarter](/maintainers/mnavarrocarter)

---

Top Contributors

[![mnavarrocarter](https://avatars.githubusercontent.com/u/17072441?v=4)](https://github.com/mnavarrocarter "mnavarrocarter (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

uuididentifierguidulidphp-extensionrfc4122rfc9562128-bit

### Embed Badge

![Health badge](/badges/castor-identifier/health.svg)

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

###  Alternatives

[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k700.2M3.3k](/packages/ramsey-uuid)[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)[pascaldevink/shortuuid

PHP 7.4+ library that generates concise, unambiguous, URL-safe UUIDs

5951.8M15](/packages/pascaldevink-shortuuid)[keiko/uuid-shortener

A simple shortener library for RFC 4122 compatible UUIDs. Change your 36 chars long UUID into it's shorter equivalent.

150215.4k2](/packages/keiko-uuid-shortener)[identifier/identifier

Common Interfaces and Factories for Identifiers

3226.2k1](/packages/identifier-identifier)[oittaa/uuid

A small PHP class for generating RFC 9562 universally unique identifiers (UUID) from version 3 to version 8.

50302.7k5](/packages/oittaa-uuid)

PHPackages © 2026

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