Check out Pux ( https://github.com/c9s/Pux ), which is targeted at extreme high performance , zero dependency, zero-overhead (with C extension support). while providing good performance, Pux also provides a Sinatra-like API for you to define your own routing paths:
$mux = new Pux\Mux;
$mux->any('/product', ['ProductController','listAction']);
$mux->get('/product/:id', ['ProductController','itemAction'] , [
'require' => [ 'id' => '\d+', ],
'default' => [ 'id' => '1', ]
]);
$mux->post('/product/:id', ['ProductController','updateAction'] , [
'require' => [ 'id' => '\d+', ],
'default' => [ 'id' => '1', ]
]);
$mux->delete('/product/:id', ['ProductController','deleteAction'] , [
'require' => [ 'id' => '\d+', ],
'default' => [ 'id' => '1', ]
]);
$route = $mux->dispatch('/product/1');
The benchmark result:
- 48.5x faster than "symfony/routing" in static route dispatching. (with pux extension installed)
- 31x faster than "symfony/routing" in regular expression dispatching. (with pux extension installed)
- 69x faster than "klein" (with pux extension installed).
n=10000
Runing php array - . 138796.45654569/s
Runing pux - . 124982.98519026/s
Runing klein - . 1801.5070399717/s
Runing ham - . 13566.734991391/s
Runing aura - . 39657.986477172/s
Runing symfony/routing - . 1934.2415677861/s
Rate Mem php array pux aura ham symfony/routing klein
php array 138.8K/s 0B ---90% -28% -9% -1% -1%
pux 124.98K/s 0B 111% -- -31%-10% -1% -1%
aura 39.66K/s 0B 349%315% ---34% -4% -4%
ham 13.57K/s 0B 1023%921% 292% -- -14% -13%
symfony/routing 1.93K/s 786K 7175%6461%2050%701% -- -93%
klein 1.8K/s 262K 7704%6937%2201%753% 107% --
================================== Bar Chart ==================================
php array 138.8K/s | ████████████████████████████████████████████████████████████ |
pux 124.98K/s | ██████████████████████████████████████████████████████ |
aura 39.66K/s | █████████████████ |
ham 13.57K/s | █████ |
symfony/routing 1.93K/s | |
klein 1.8K/s | |
============================== System Information ==============================
PHP Version: 5.5.6
CPU Brand String: Intel(R) Core(TM) i5-3427U CPU @ 1.80GHz
With XDebug Extension.
Pux tries not to consume computation time to build all routes dynamically (like Symfony/Routing). Instead, Pux compiles your routes to plain PHP array for caching, the compiled routes can be loaded from cache very fast.
With Pux PHP Extension support, you may load and dispatch the routes 1.5~2x faster than pure PHP Pux.