Download the PHP package wilaak/radix-router without Composer

On this page you can find all versions of the php package wilaak/radix-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package radix-router

RadixRouter

Simple radix tree based HTTP request router for PHP. Lightweight and high-performance (see benchmarks)

Overview

How does it work?

The router splits the path into segments and walks the tree, matching each segment in order. Because the tree only branches where routes differ, the router can quickly skip irrelevant routes and find the correct handler with minimal comparisons.

Install

Install with composer:

composer require wilaak/radix-router

Or simply include it in your project:

Requires PHP 8.0 or newer. (PHP 8.3 for tests)

Usage Example

Here's a basic usage example using the typical PHP-FPM (FastCGI) web environment:

Registering Routes

Routes are registered using the add() method. You can assign any value as the handler. The order of route matching is: static > parameter.

Note: Trailing slashes are ignored. For example, both /about and /about/ are treated as the same route.

Below is an example showing the different ways to define routes:

How to Cache Routes

Rebuilding the route tree on every request or application startup can slow down performance.

Note: Anonymous functions (closures) are not supported for route caching because they cannot be serialized. When caching routes, only use handlers that can be safely represented as strings, arrays, or serializable objects.

Note: When implementing route caching, care should be taken to avoid race conditions when rebuilding the cache file. Ensure that the cache is written atomically so that each request can always fully load a valid cache file without errors or partial data.

Here is a simple cache implementation:

By storing your routes in a PHP file, you let PHP’s OPcache handle the heavy lifting, making startup times nearly instantaneous.

Note on HEAD Requests

According to the HTTP specification, any route that handles a GET request should also support HEAD requests. RadixRouter does not automatically add this behavior. If you are running outside a standard web server environment (such as in a custom server), ensure that your GET routes also respond appropriately to HEAD requests. Responses to HEAD requests must not include a message body.

Benchmarks

Single-threaded benchmark (Xeon E-2136, PHP 8.4.8 cli OPcache enabled):

Simple App (33 Routes)

Router Register Lookups Memory Usage Peak Memory
RadixRouter 0.04 ms 3,233,227/sec 375 KB 456 KB
FastRoute 1.85 ms 2,767,883/sec 431 KB 1,328 KB
SymfonyRouter 6.24 ms 1,722,432/sec 574 KB 1,328 KB

Avatax API (256 Routes)

Router Register Lookups Memory Usage Peak Memory
RadixRouter 0.25 ms 2,127,808/sec 587 KB 588 KB
FastRoute 4.94 ms 707,516/sec 549 KB 1,328 KB
SymfonyRouter 12.60 ms 1,182,060/sec 1,292 KB 1,588 KB

Bitbucket API (178 Routes)

Router Register Lookups Memory Usage Peak Memory
RadixRouter 0.17 ms 1,781,226/sec 532 KB 533 KB
FastRoute 3.81 ms 371,104/sec 556 KB 1,328 KB
SymfonyRouter 12.16 ms 910,064/sec 1,186 KB 1,426 KB

License

This library is licensed under the WTFPL-2.0. Do whatever you want with it.


All versions of radix-router with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wilaak/radix-router contains the following files

Loading the files please wait ....