https://github.com/zqhong/route
A fast router for PHP
https://github.com/zqhong/route
fast php route
Last synced: 11 months ago
JSON representation
A fast router for PHP
- Host: GitHub
- URL: https://github.com/zqhong/route
- Owner: zqhong
- License: mit
- Created: 2017-03-06T13:59:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-13T10:25:01.000Z (over 7 years ago)
- Last Synced: 2024-04-22T19:21:30.379Z (about 2 years ago)
- Topics: fast, php, route
- Language: PHP
- Size: 25.4 KB
- Stars: 27
- Watchers: 5
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Route - A fast route implemented by php
[](https://styleci.io/repos/84079657)
[](https://travis-ci.org/zqhong/route)
[](https://scrutinizer-ci.com/g/zqhong/route/?branch=master)
`zqhong/route` is inspred by [nikic/FastRoute](https://github.com/nikic/FastRoute). But it is faster than `FastRoute`.
* [README English](README.md)
* [README 简体中文](README_ZH_CN.md)
---
# Install
```
$ composer require -vvv "zqhong/route:dev-master"
```
# Example
```
addRoute('GET', '/user/{id:\d+}', 'getUser');
});
$httpMethod = 'GET';
$uri = '/user/1';
$routeInfo = $routeDispatcher->dispatch($httpMethod, $uri);
if (Arr::getValue($routeInfo, 'isFound')) {
$handler = Arr::getValue($routeInfo, 'handler');
$params = Arr::getValue($routeInfo, 'params');
call_user_func_array($handler, $params);
} else {
echo '404 NOT FOUND';
}
```
Using CURL send request:
```
// return 404 NOT FOUND
$ curl http://example.com/?r=ops
// return Your uid: 1
$ curl http://example.com/?=/user/1
```
---
# Benchmark
## Environment
* OS:Ubuntu 16.04 LTS(Vultr 4Cores 8G memory)
* PHP:7.0.4
* Apache:2.4.18
## Result

```
nikic_route(v1.2)
Requests per second: 3527.98 [#/sec] (mean)
symfony route(v3.2)
Requests per second: 5193.17 [#/sec] (mean)
zqhong route(dev-master)
Requests per second: 5923.56 [#/sec] (mean)
```
Benchmark test code and result in `benchmark` folder.
---
# Document
[How it works](http://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-expressions.html)