Pux 是一个超级高性能的 PHP 路由器,是对 PHP Router 的重新设计。测试速度比 symfony 快 48.5 倍,比正则表达式方式路由快 31 倍。
路由匹配示例:
/post /post/:id => matches /post/33 /post/:id(/:title) => matches /post/33, /post/33/post%20title /post/:id(\.:format) => matches /post/33, /post/33.json .. /post/33.xml
示例代码:
require 'vendor/autoload.php'; // use PCRE patterns you need Pux\PatternCompiler class. use Pux\Executor; class ProductController { public function listAction() { return 'product list'; } public function itemAction($id) { return "product $id"; } } $mux = new Pux\Mux; $mux->add('/product', ['ProductController','listAction']); $mux->add('/product/:id', ['ProductController','itemAction'] , [ 'require' => [ 'id' => '\d+', ], 'default' => [ 'id' => '1', ] ]); $route = $mux->dispatch('/product/1'); Executor::execute($route);