// the find
nikic/FastRoute
Fast request router for PHP
FastRoute is a regex-based HTTP router for PHP by nikic (one of PHP's core contributors). It compiles all your routes into a single optimized regex rather than looping through them one at a time, which makes dispatch time nearly constant regardless of route count. It's for PHP developers who need a standalone router without pulling in a full framework.
The core algorithm is genuinely clever — combining routes into a single regex with mark/groupcount tricks avoids the O(n) per-request cost of naive routers; the linked blog post is worth reading. URI generation was added (GenerateUri namespace) so you're not stuck reverse-engineering your own routes. PSR-16 cache support means you can plug in any cache backend instead of being stuck with the file-based one. The project has static analysis, BC checks, benchmarks, and coding standards all in CI — unusual care for a library this focused.
Optional segments are trailing-only, which is a real constraint for API versioning patterns like /v{version}/users — you have to register routes separately. The dispatch result is still a raw array (index 0 is the status code, index 1 is the handler) in the default API; the newer Result objects exist but aren't the default path, so you can end up with inconsistent code across a project. No middleware or pipeline concept at all — this is by design, but if your team expects anything Rack/PSR-15-shaped, you're wiring that yourself. Route groups only add a prefix, so there's no way to attach shared constraints or defaults to a group.