支持多种编程语言混合开发web应用的通用服务器hi-nginx-1.4.2已经发布了。
此次发布包含多项重要更新:
- 支持python2和3,通过编译选项--
with-http-hi-python-version
- 删除boost.python依赖,优化python3兼容性,性能有所提高
- 支持lua和luajit,通过编译选项
--with-http-hi-lua-version
- 为python专门定制了hi.py框架,单一入口,类似bottle或者flask一样,对性能有一定影响,但还是比bottle和flask快得多
- 为php7专门定制了类似hi.py的微型框架,单一入口,类似bottle或者flask,对性能没什么影响
hi.py示例:
1 from hi import hi
2 app =hi()
3
4 @app.route(r'^/test/?$',['GET','POST'])
5 @app.route(r"^/$",['GET'])
6 def hello_world(req,res,param):
7 res.header('Content-Type','text/plain;charset=utf-8')
8 res.content('hello,world')
9 res.status(200)
10
11 @app.route(r"^/client/?$",['GET','POST'])
12 def client(req,res,param):
13 res.content('{}<br>{}<br>{}<br>{}<br>{}'.format(req.client(),req.method(),req.uri(),req.user_agent(),req.param()))
14 res.status(200)
15
16 @app.route(r"^/hello/(?P<who>\w+)?$",['GET'])
17 def hello(req,res,param):
18 res.content('{}={}'.format('who',param['who']))
19 res.status(200)
20
21
22
23 if __name__ == '__main__':
24 app.run(hi_req,hi_res)
php7示例代码:
require_once 'hi/servlet.php';
require_once 'hi/route.php';
class index implements \hi\servlet {
public function handler(\hi\request $req, \hi\response $res) {
$app = \hi\route::get_instance();
$app->add('{^/$}', array('GET'), function ($rq, $rs, &$param) {
$rs->content = 'hello,world';
$rs->status = 200;
});
$app->add('{^/who/(?P<name>\w+)/?$}', array('GET'), function ($rq, $rs, &$param) {
$rs->content = 'hello,'.$param['name'];
$rs->status = 200;
});
$app->add('{^/phpinfo/?$}', array('GET'), function($rq, $rs, &$param) {
ob_start();
phpinfo();
$rs->content = ob_get_contents();
$rs->status = 200;
ob_end_clean();
});
$app->run($req, $res);
}
}
简介:
它既是 web 服务器,也是 application 服务器。
它是 NGINX 的超集。
它性能强劲,易于开发,部署方便。
它支持多种语言混合开发 web 应用: