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

Minimal high-performance radix tree based HTTP request router for PHP (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 SAPI 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 > wildcard.

Note: Paths are normalized by removing trailing slashes. For example, both /about and /about/ will be treated as the same route.

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

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.

How to Cache Routes

You can most likely ignore this section. Most SAPI environments are generally limited by I/O due to their synchronous nature, so the time spent reconstructing routes is gonna be minimal compared to the overall I/O wait time.

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.

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.05 ms 2,977,816/sec 384 KB 458 KB
FastRoute 1.92 ms 2,767,883/sec 429 KB 1,337 KB
SymfonyRouter 6.84 ms 1,722,432/sec 573 KB 1,338 KB

Avatax API (256 Routes)

Router Register Lookups Memory Usage Peak Memory
RadixRouter 0.27 ms 2,006,929/sec 688 KB 690 KB
FastRoute 4.94 ms 707,516/sec 549 KB 1,337 KB
SymfonyRouter 12.60 ms 1,182,060/sec 1,291 KB 1,587 KB

Bitbucket API (178 Routes)

Router Register Lookups Memory Usage Peak Memory
RadixRouter 0.23 ms 1,623,718/sec 641 KB 643 KB
FastRoute 3.81 ms 371,104/sec 555 KB 1,337 KB
SymfonyRouter 12.16 ms 910,064/sec 1,180 KB 1,419 KB

License

This library is licensed under the WTFPL-2.0 license. 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 ....