DEV Community

Sylvain PHILIP
Sylvain PHILIP

Posted on • Updated on

Piko router, a lightweight and blazing fast router for PHP

I recently wrote a new PHP router (Piko router) that stick out from the others by its implementation.

Unlike popular PHP routers, Piko router doesn't solve the problem of route matching using regular expressions. Instead of that, it uses a radix trie structure to store routes definitions and a search algorithm to retrieve them against a given path. This approach is very efficient because the search consist just to traverse a prefix tree.

I found libraries in other programming languages that use this approach : matchit (Rust), find-my-way (Javascript), fasthttp (Go) But, curiously, no one in PHP. That's why I decided to bring my contribution to have the same approach in PHP.

To demonstrate this search efficiency, I wrote some benchmark tests to compare Piko router against Fastroute and Symfony Router which are references in their domain.

Routers benchmark over 5000 routes

Piko router was initially designed to be used in the Piko framework (another project I made) but it can be embedded as a standalone dependency in third party application via composer.

Discussion (0)