a high performance, lightweight framework for php5 & php7 written in c
一款使用 C
语言写成的、现代的高性能轻量级PHP
web
框架。
####see README_en.md for english introduction.
在以下的场景中,每个数据库请求和curl请求都将需要1秒的等待时间,如果完全使用传统同步阻塞方案,完成全部将总共需要6秒的时间。
使用普通的PHP原生异步解决方案时,MySQL和curl将各需要1秒等待时间,此时完成全部请求将总共需要2秒时间,可3倍的提升响应速度。
但使用 air framework 的全局异步并发模式,完成全部的6个请求将总共只需要1秒等待时间,轻而易举即可取得6倍的响应性能提升。
<?php
/**
* air\config::path_get('mysql.config.air');
* @see https://github.com/wukezhan/air/blob/master/tests/003.curl.phpt
* @see https://github.com/wukezhan/air/blob/master/tests/mysql.inc.php
* @see https://github.com/wukezhan/air/blob/master/tests/004.mysql.phpt
*/
define('URL', 'http://localhost/test/sleep');
$time = microtime(1);
$t = 1;
// each request below will use 1 second
$m1 = new mysql(DB_CONF);
$m1->async()->query("select sleep({$t}) as a");
$m2 = new mysql(DB_CONF);
$m2->async()->query("select sleep({$t}) as b");
$m3 = new mysql(DB_CONF);
$m3->async()->query("select sleep({$t}) as b");
$c1 = new curl();
$c1->async()->get(URL , ['sleep' => $t]);
$c2 = new curl();
$c2->async()->get(URL , ['sleep' => $t]);
$c3 = new curl();
$c3->async()->get(URL , ['sleep' => $t]);
var_dump($c3->data());
var_dump($c1->data());
var_dump($c2->data());
var_dump($m1->data());
var_dump($m2->data());
var_dump($m3->data());
echo "time used: ", microtime(1)-$time,"s\n";
// this will totally use 1 second but not 6 seconds
# configure options
./configure --prefix=/path/to/php --enable-mysqlnd --with-mysqli --with-curl
对于 docker 用户,可以通过以下命令一键体验 air framework
# php5
docker run -it -p 2355:80 --name=airstack5 wukezhan/airstack5
# visit
curl http://localhost:2355/
# or
curl http://localhost:2355/hello/world
#php7
docker run -it -p 2357:80 --name=airstack7 wukezhan/airstack7
# visit
curl http://localhost:2357/
# or
curl http://localhost:2357/hello/world
# 1. 准备源码
## 下载并解压缩源码包
### php5
https://github.com/wukezhan/air/archive/master.zip
### php7
https://github.com/wukezhan/air/archive/php7.zip
### 或从源码克隆
git clone https://github.com/wukezhan/air
cd air
# 对于克隆源码,可执行以下命令切换到 php7 分支
git checkout php7
# 2. 编译安装
/path/to/php/bin/phpize
./configure --with-php-config=/path/to/php/bin/php-config
make && make install
make test
# 3. 修改配置
vim /path/to/php/lib/php.ini
增加以下配置:
extension = air.so
对本项目感兴趣的朋友,可以关注微博 weibo.com/wukezhan 或通过以下方式进行交流: