PHPackages                             piko/router - 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. [API Development](/categories/api)
4. /
5. piko/router

ActiveLibrary[API Development](/categories/api)

piko/router
===========

One of the fastest PHP router, using a radix trie to retrieve routes

v3.1.1(3y ago)6643222LGPL-3.0-or-laterPHPPHP &gt;=7.1.0

Since Sep 24Pushed 3y ago2 watchersCompare

[ Source](https://github.com/piko-framework/router)[ Packagist](https://packagist.org/packages/piko/router)[ Docs](https://github.com/piko-framework/router)[ RSS](/packages/piko-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (8)Used By (2)

Piko Router
===========

[](#piko-router)

[![build](https://github.com/piko-framework/router/actions/workflows/php.yml/badge.svg)](https://github.com/piko-framework/router/actions/workflows/php.yml)[![Coverage Status](https://camo.githubusercontent.com/ad03f8cf94324b4d3cd68463e9134a953f9ccc6974507fbe40b8cdd61aa63d17/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70696b6f2d6672616d65776f726b2f726f757465722f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/piko-framework/router?branch=main)

A lightweight and blazing fast router (see [benchmarks](#benchmarks)) using a [radix trie](https://en.wikipedia.org/wiki/Radix_tree) to store dynamic routes.

This router maps routes to user defined handlers and can do the reverse operation (reverse routing).

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

[](#installation)

It's recommended that you use Composer to install Piko Router.

```
composer require piko/router
```

Usage
-----

[](#usage)

A basic example:

```
use Piko\Router;

$router = new Router();
$router->addRoute('/', 'homeView');
$router->addRoute('/user/:id', 'userView');

$match = $router->resolve('/');
echo $match->handler; // homeView

$match = $router->resolve('/user/10');
echo $match->handler; // userView
echo $match->params['id']; // 10

// Use of the $match->handler to dispatch an action
// ...

// Reverse routing
echo $router->getUrl('homeView'); // /
echo $router->getUrl('userView', ['id' => 3]); // /user/3
```

Dynamic handlers:

```
use Piko\Router;

$router = new Router();
$router->addRoute('/admin/:module/:action', ':module/admin/:action');

$match = $router->resolve('/admin/user/add');
echo $match->handler; // user/admin/add

echo $router->getUrl('blog/admin/index'); // /admin/blog/index
```

Advanced usage: [See RouterTest.php](tests/RouterTest.php)

Benchmarks
----------

[](#benchmarks)

Piko router comparison against Fastroute (cached) and Symfony router (cached).

### Benchmark against 1000 generated routes

[](#benchmark-against-1000-generated-routes)

```
./vendor/bin/phpbench run --revs=10000 --report='extends:aggregate,break:["benchmark"]'
```

```
SymfonyRouter
+--------------------+--------------+-------+-----+----------+---------+--------+
| subject            | set          | revs  | its | mem_peak | mode    | rstdev |
+--------------------+--------------+-------+-----+----------+---------+--------+
| benchStaticRoutes  | Best Case    | 10000 | 5   | 7.241mb  | 1.243μs | ±2.00% |
| benchStaticRoutes  | Average Case | 10000 | 5   | 7.241mb  | 1.296μs | ±2.40% |
| benchStaticRoutes  | Worst Case   | 10000 | 5   | 7.241mb  | 1.267μs | ±2.35% |
| benchDynamicRoutes | Best Case    | 10000 | 5   | 7.241mb  | 2.007μs | ±1.64% |
| benchDynamicRoutes | Average Case | 10000 | 5   | 7.241mb  | 1.984μs | ±1.87% |
| benchDynamicRoutes | Worst Case   | 10000 | 5   | 7.241mb  | 1.929μs | ±1.69% |
+--------------------+--------------+-------+-----+----------+---------+--------+

PikoRouter
+--------------------+--------------+-------+-----+----------+---------+--------+
| subject            | set          | revs  | its | mem_peak | mode    | rstdev |
+--------------------+--------------+-------+-----+----------+---------+--------+
| benchStaticRoutes  | Best Case    | 10000 | 5   | 1.862mb  | 0.327μs | ±1.78% |
| benchStaticRoutes  | Average Case | 10000 | 5   | 1.862mb  | 0.330μs | ±2.37% |
| benchStaticRoutes  | Worst Case   | 10000 | 5   | 1.862mb  | 0.318μs | ±1.61% |
| benchDynamicRoutes | Best Case    | 10000 | 5   | 1.862mb  | 1.308μs | ±1.51% |
| benchDynamicRoutes | Average Case | 10000 | 5   | 1.862mb  | 1.800μs | ±0.72% |
| benchDynamicRoutes | Worst Case   | 10000 | 5   | 1.862mb  | 1.735μs | ±2.64% |
+--------------------+--------------+-------+-----+----------+---------+--------+

FastRoute
+--------------------+--------------+-------+-----+----------+----------+--------+
| subject            | set          | revs  | its | mem_peak | mode     | rstdev |
+--------------------+--------------+-------+-----+----------+----------+--------+
| benchStaticRoutes  | Best Case    | 10000 | 5   | 3.155mb  | 0.228μs  | ±2.46% |
| benchStaticRoutes  | Average Case | 10000 | 5   | 3.155mb  | 0.213μs  | ±1.19% |
| benchStaticRoutes  | Worst Case   | 10000 | 5   | 3.155mb  | 0.235μs  | ±1.60% |
| benchDynamicRoutes | Best Case    | 10000 | 5   | 3.155mb  | 0.652μs  | ±1.36% |
| benchDynamicRoutes | Average Case | 10000 | 5   | 3.155mb  | 12.908μs | ±1.13% |
| benchDynamicRoutes | Worst Case   | 10000 | 5   | 3.155mb  | 31.784μs | ±1.53% |
+--------------------+--------------+-------+-----+----------+----------+--------+

```

[![Routers match against 1000 routes](benchmark/img/bench_1000_routes.png)](benchmark/img/bench_1000_routes.png)

### Benchmark against 5000 generated routes

[](#benchmark-against-5000-generated-routes)

```
ROUTES=5000 ./vendor/bin/phpbench run --revs=10000 --report='extends:aggregate,break:["benchmark"]'
```

```
SymfonyRouter
+--------------------+--------------+-------+-----+----------+---------+--------+
| subject            | set          | revs  | its | mem_peak | mode    | rstdev |
+--------------------+--------------+-------+-----+----------+---------+--------+
| benchStaticRoutes  | Best Case    | 10000 | 5   | 31.488mb | 3.911μs | ±2.47% |
| benchStaticRoutes  | Average Case | 10000 | 5   | 31.488mb | 3.709μs | ±1.78% |
| benchStaticRoutes  | Worst Case   | 10000 | 5   | 31.488mb | 3.771μs | ±1.40% |
| benchDynamicRoutes | Best Case    | 10000 | 5   | 31.488mb | 4.775μs | ±1.74% |
| benchDynamicRoutes | Average Case | 10000 | 5   | 31.488mb | 4.844μs | ±0.46% |
| benchDynamicRoutes | Worst Case   | 10000 | 5   | 31.488mb | 5.657μs | ±2.16% |
+--------------------+--------------+-------+-----+----------+---------+--------+

PikoRouter
+--------------------+--------------+-------+-----+----------+---------+--------+
| subject            | set          | revs  | its | mem_peak | mode    | rstdev |
+--------------------+--------------+-------+-----+----------+---------+--------+
| benchStaticRoutes  | Best Case    | 10000 | 5   | 4.569mb  | 0.312μs | ±1.82% |
| benchStaticRoutes  | Average Case | 10000 | 5   | 4.569mb  | 0.313μs | ±1.01% |
| benchStaticRoutes  | Worst Case   | 10000 | 5   | 4.569mb  | 0.313μs | ±0.40% |
| benchDynamicRoutes | Best Case    | 10000 | 5   | 4.569mb  | 1.242μs | ±1.92% |
| benchDynamicRoutes | Average Case | 10000 | 5   | 4.569mb  | 1.897μs | ±1.36% |
| benchDynamicRoutes | Worst Case   | 10000 | 5   | 4.569mb  | 1.947μs | ±2.04% |
+--------------------+--------------+-------+-----+----------+---------+--------+

FastRoute
+--------------------+--------------+-------+-----+----------+-----------+--------+
| subject            | set          | revs  | its | mem_peak | mode      | rstdev |
+--------------------+--------------+-------+-----+----------+-----------+--------+
| benchStaticRoutes  | Best Case    | 10000 | 5   | 11.248mb | 0.208μs   | ±1.44% |
| benchStaticRoutes  | Average Case | 10000 | 5   | 11.248mb | 0.211μs   | ±1.33% |
| benchStaticRoutes  | Worst Case   | 10000 | 5   | 11.248mb | 0.225μs   | ±1.51% |
| benchDynamicRoutes | Best Case    | 10000 | 5   | 11.248mb | 0.584μs   | ±1.96% |
| benchDynamicRoutes | Average Case | 10000 | 5   | 11.248mb | 85.164μs  | ±1.09% |
| benchDynamicRoutes | Worst Case   | 10000 | 5   | 11.248mb | 171.611μs | ±0.84% |
+--------------------+--------------+-------+-----+----------+-----------+--------+

```

[![Routers match against 5000 routes](benchmark/img/bench_5000_routes.png)](benchmark/img/bench_5000_routes.png)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.6% 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 ~87 days

Recently: every ~126 days

Total

7

Last Release

1171d ago

Major Versions

v1.0 → v2.02021-10-06

v2.2 → v3.02022-10-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/001b70c85d853a2aae5f1bf74a1ff7ad77ffcec2d423090d67293bde99158350?d=identicon)[ilhooq](/maintainers/ilhooq)

---

Top Contributors

[![ilhooq](https://avatars.githubusercontent.com/u/1500886?v=4)](https://github.com/ilhooq "ilhooq (35 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")[![vanodevium](https://avatars.githubusercontent.com/u/16780069?v=4)](https://github.com/vanodevium "vanodevium (1 commits)")

---

Tags

phpradixradix-treeradix-trierouterroutingmicrorouterradixmicro-router

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/piko-router/health.svg)

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

###  Alternatives

[phroute/phroute

Fast, fully featured restful request router for PHP

739462.1k29](/packages/phroute-phroute)[pear2/net_routeros

This package allows you to read and write information from a RouterOS host using MikroTik's RouterOS API.

248111.7k4](/packages/pear2-net-routeros)[tobion/openapi-symfony-routing

Loads routes in Symfony based on OpenAPI/Swagger annotations

4219.5k](/packages/tobion-openapi-symfony-routing)[szenis/routing

A small and simple PHP router

162.4k2](/packages/szenis-routing)

PHPackages © 2026

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