php7的效率是php5的一倍,而yaf框架又是由C语言写的最快的框架,两者的结合应该是比较理想的架构。这里在自己的环境上安装和使用php7下的yaf
一 安装php7
我已经介绍过php7的安装:http://1.chunwei.sinaapp.com/?p=257
照着步骤安装即可
二 安装yaf
1, 到git上下载鸟哥的php7兼容版本:https://github.com/laruence/yaf/tree/php7
2,执行
/usr/local/php7/bin/phpize ./configure --with-php-config=/usr/local/php7/bin/php-config make && make install
3,添加扩展
打开 vim /usr/local/php7/etc/php.ini
添加
[yaf]
extension=yaf.so
4,顺手创建一个例子
在yaf
/yaf-php7/tools/cg
下执行
php yaf_cg web
这里产生了一个web的文件夹实例
三 配置nginx
server { listen 8080; root /usr/www/web; location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; } location / { try_files $uri $uri/ /index.php?$query_string; } }
四 测试
最后打开你的浏览器访问http://localhost:8080/index.php就可以看到输出Hello World! I am Stranger的实例了。这就代表了yaf已经安装成功。
压测一下自己的ab -n 50 -c 10 localhost:8080/index.php/
结果还是很赞的
最后 改进
听鸟哥的话:
http://www.laruence.com/2015/12/04/3086.html
添加opcache配置
opcache.enable=1 opcache.enable_cli=1 opcache.huge_code_pages=1 opcache.file_cache=/tmp