PHPackages                             sirix/mezzio-radixrouter - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. sirix/mezzio-radixrouter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

sirix/mezzio-radixrouter
========================

RadixRouter integration for Mezzio

3.2.1(2mo ago)11.1k1MITPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jul 13Pushed 2mo agoCompare

[ Source](https://github.com/sirix777/mezzio-radixrouter)[ Packagist](https://packagist.org/packages/sirix/mezzio-radixrouter)[ Fund](https://buymeacoffee.com/sirix)[ GitHub Sponsors](https://github.com/sirix777)[ RSS](/packages/sirix-mezzio-radixrouter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (26)Versions (8)Used By (1)

Mezzio RadixRouter
==================

[](#mezzio-radixrouter)

[![Latest Stable Version](https://camo.githubusercontent.com/3eace188900e61657b523652e55fb2e53030a2cebc5aa608c6fae8de8c921f76/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d7261646978726f757465722f76)](https://packagist.org/packages/sirix/mezzio-radixrouter)[![Total Downloads](https://camo.githubusercontent.com/f01f7da30602ff3f14a6b2922c2cc2d3dde0872234dce7905d4a3a6f8c71ca8a/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d7261646978726f757465722f646f776e6c6f616473)](https://packagist.org/packages/sirix/mezzio-radixrouter)[![Latest Unstable Version](https://camo.githubusercontent.com/b496bd266e5447dcd6a1bccc690da527ed13be62c40e1cd243b9e6202ffc0099/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d7261646978726f757465722f762f756e737461626c65)](https://packagist.org/packages/sirix/mezzio-radixrouter)[![License](https://camo.githubusercontent.com/4e194b3494d674caada2f0fef1728a5be28ceaef3a833e78ca352f45d31b2289/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d7261646978726f757465722f6c6963656e7365)](https://packagist.org/packages/sirix/mezzio-radixrouter)[![PHP Version Require](https://camo.githubusercontent.com/eebe37a35f26faa7d59374476990698c4b25a6030243d8e970424747fe4854f1/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d7261646978726f757465722f726571756972652f706870)](https://packagist.org/packages/sirix/mezzio-radixrouter)

RadixRouter integration for [Mezzio](https://docs.mezzio.dev/), providing high-performance HTTP routing using a radix tree algorithm.

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

[](#installation)

Install this package via Composer:

```
composer require sirix/mezzio-radixrouter
```

Features
--------

[](#features)

- High-performance routing using a radix tree algorithm
- PSR-7 and PSR-15 compatible
- Supports route parameters and optional parameters
- Route caching for improved performance
- Fully compatible with Mezzio middleware architecture

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

There are two ways to set up RadixRouter in your Mezzio application:

#### Automatic Configuration (Recommended)

[](#automatic-configuration-recommended)

The easiest way to set up RadixRouter is to use the provided ConfigProvider, which automatically registers all necessary dependencies:

```
// In config/config.php or similar configuration file
$aggregator = new ConfigAggregator([
    // ... other config providers
    \Sirix\Mezzio\Router\RadixRouter\ConfigProvider::class,
    // ... other config providers
]);
```

This will automatically register the RadixRouter as the default router implementation for your application.

#### Manual Configuration

[](#manual-configuration)

Alternatively, you can manually update your dependencies configuration:

```
// In config/autoload/dependencies.php or similar configuration file
use Mezzio\Router\RouterInterface;
use Sirix\Mezzio\Router\RadixRouter;
use Sirix\Mezzio\Router\RadixRouterFactory;

return [
    'dependencies' => [
        'factories' => [
            RouterInterface::class => RadixRouterFactory::class,
        ],
    ],
];
```

### Route Configuration

[](#route-configuration)

Routes can be defined in your Mezzio application as usual:

```
// In config/routes.php or similar
$app->get('/api/users', [UserListHandler::class], 'api.users');
$app->get('/api/users/:id', [UserDetailsHandler::class], 'api.user');
$app->post('/api/users', [CreateUserHandler::class]);
```

#### Radix-specific route patterns

[](#radix-specific-route-patterns)

The Radix router supports a few convenient path patterns that may not be available in all Mezzio routers. Here are some examples:

- Optional parameter at the end

```
// Matches both "/hello" and "/hello/john"
$app->get('/hello/:name?', [HelloHandler::class], 'hello');
// In the handler, you can access $request->getAttribute('name'); // null or "john"
```

- Multiple optional parameters in sequence

```
// Matches: "/archive", "/archive/2025", "/archive/2025/08"
$app->get('/archive/:year?/:month?', [ArchiveHandler::class], 'archive');
// Attributes:
//   year  => null or e.g. "2025"
//   month => null or e.g. "08"
```

- Trailing wildcard (catch-all) segment

```
// Matches any sub-path under /files, e.g. "/files", "/files/images/cat.png"
$app->get('/files/:path*', [FilesHandler::class], 'files');
// Attribute:
//   path => '' (empty string) for "/files" or the full remainder like "images/cat.png"
```

Notes:

- Parameter names are defined with a preceding colon (:) and become request attributes.
- A question mark (?) makes the parameter optional.
- An asterisk (\*) after a parameter name captures the remainder of the path as a single string.
- Use route names (third argument) as needed for URL generation or identification.

### Caching Configuration

[](#caching-configuration)

To enable route caching for improved performance:

```
// In config/autoload/router.global.php or similar
use Sirix\Mezzio\Router\Enum\CacheConfig;

return [
    'router' => [
        'radix' => [
            CacheConfig::Enabled->value => true,
            CacheConfig::File->value => 'data/cache/radix-cache.php',
        ],
    ]
];
```

Documentation
-------------

[](#documentation)

For more information about routing in Mezzio, please refer to the [Mezzio routing documentation](https://docs.mezzio.dev/mezzio/v3/features/router/intro/).

Benchmarks
----------

[](#benchmarks)

Performance benchmarks comparing RadixRouter with other Mezzio routers (FastRoute, LaminasRouter) are available in the [benchmark-comparison](./benchmark-comparison) directory.

For detailed results and methodology, see [benchmark-comparison/README.md](./benchmark-comparison/README.md).

### Quick Results (33 routes, JIT=tracing)

[](#quick-results-33-routes-jittracing)

RankRouterLookups/secMem (KB)Register (ms)1**MezzioRadixRouterCached**1,279,43045.10.0732**MezzioRadixRouter**1,256,213178.70.1493**MezzioFastRouteCached**294,00142.90.1114**MezzioFastRoute**137,812137.60.1945**MezzioLaminasRouter**56,560371.00.483MezzioRadixRouter is **~9x faster** than FastRoute and **~22x faster** than LaminasRouter in this test.

License
-------

[](#license)

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

Credits
-------

[](#credits)

- [Sirix](https://github.com/sirix777) - Project maintainer
- [Wilaak RadixRouter](https://github.com/Wilaak/RadixRouter) - The underlying radix tree router implementation
- [Mezzio](https://github.com/mezzio/mezzio) - The middleware framework

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance86

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community8

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

Every ~46 days

Recently: every ~57 days

Total

6

Last Release

70d ago

Major Versions

1.0.0 → 2.0.02025-07-18

2.0.0 → 3.0.02025-08-30

PHP version history (2 changes)1.0.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

3.1.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ecccf9003c061847e877eeea3bdf1b382f6f9dbb11d33112d6b2740bf0533f9?d=identicon)[sirix777](/maintainers/sirix777)

---

Top Contributors

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

---

Tags

httppsrpsr-7middlewarelaminasmezzioRadixRouter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sirix-mezzio-radixrouter/health.svg)

```
[![Health](https://phpackages.com/badges/sirix-mezzio-radixrouter/health.svg)](https://phpackages.com/packages/sirix-mezzio-radixrouter)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-fastroute

FastRoute integration for Mezzio

162.7M52](/packages/mezzio-mezzio-fastroute)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.0M61](/packages/mezzio-mezzio-router)[mezzio/mezzio-helpers

Helper/Utility classes for Mezzio

134.3M67](/packages/mezzio-mezzio-helpers)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)

PHPackages © 2026

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