Elliot Levin

I enjoy making things


About me

Github Profile



Recent Posts

Productivity with Personal Projects10 Dec 2014

Measuring Progress as a Programmer06 Nov 2014

My Story as a Teenage Programmer24 Sep 2014

View All


Another exceptionally fast PHP router

RapidRoute is another little side project of mine that was heavily inspired by nikic's FastRoute and the seemingly endless pursuit of ultra fast uri routing in PHP. The goal of the package not just to match pretty urls into useful data telling the application what to do but to do it fast, very fast.

The traditional method of routing, as used by FastRoute, is by compiling the route definitions to regular expressions which will be run against the url. RapidRoute takes a somewhat different approach to this problem by compiling the route definitions to PHP code. This has the benefit of allowing much room for optimization. Specifically, minimizing the number of comparisons necessary to match a route and using native PHP functions instead of regular expressions when available. The obvious downside is now being limited to speed of PHP itself, but with PHP7 currently in the works and much hype about substantial performance gains, who knows what is possible?

RapidRoute, as it stands, is pretty much a working implementation at this point. It is well tested with 99% code coverage and implements all the necessary API for usage in a framework or as a standalone package. In terms of performance (of non-realistic benchmarks), when compared to FastRoute, the results are mixed. For static routes FastRoute is a clear winner but for dynamic routes, non-existent routes (404) and invalid HTTP method (405) RapidRoute shows substantial performance improvements.

You can view the repository here