express on the php-swoole. High performance web framework based on swoole.
it works on the php-swoole extension,Please make sure to install the swoole extension!
The advantage of the framework is to use the asynchronous process, swoole thread and process technology, so be sure to use asynchronous, in the use of I/O and network requests such as fs/FS:: readFileAsync, fs/FS:: writeFileAsync, http/Http:: getAsync, http/Http:: postAsync etc..
use cube\App;
$router = App::Router();
$router->on(function($req,$res,$next){
//your logic code.
});
$router->on('/',function($req,$res,$next){
if($req->post->authcode == 'xxx'){
$next();
}else{
$res->send('503');
}
});
$router->on('/user',function($req,$res,$next){
//login check.
});
$router->on('/upload','router/upload.php');
$router->on('/filter',[
function($req,$res,$next){
//exec the middleware on /filter.
},
function($req,$res,$next){
//exec the middleware on /filter.
}
]);
$router->on(['/filter1','/filter2'],[
function($req,$res,$next){
//exec the middleware on /filter.
},
function($req,$res,$next){
//exec the middleware on /filter.
}
]);bin/www.php
//include all cube libs.
require __DIR__ . '/../modules/cube/App.php';
//initialize the cube framework.
\cube\App::init([
'debug' => 1,
'error_report' => 1,
'base_dir' => __DIR__ . '/../',
'time_zone' => 'Asia/Shanghai',
'ssl_cert_file' => '',
'ssl_key_file' => '',
'modules' => [
'modules/session/autoload.php',
'modules/favicon/autoload.php',
]
]);app.php
$app = App::Router();
//session parser middleware.
//$app->on(RedisSession::create());
//add common middleware.
$app->on(\favicon\Favicon::create());In fact, the favicon middleware returns ['/favicon',function($req,$res,$next){//...}];