PHP开启opcache提升代码性能


Posted in PHP onApril 26, 2015

配置指令如下:

[opcache]
zend_extension=opcache.so
opcache.enable_cli=1
;共享内存大小, 这个根据你们的需求可调
opcache.memory_consumption=256   
;interned string的内存大小, 也可调
opcache.interned_strings_buffer=8
;最大缓存的文件数目
opcache.max_accelerated_files=4000
;60s检查一次文件更新
opcache.revalidate_freq=60
;打开快速关闭, 打开这个在PHP Request Shutdown的时候 会收内存的速度会提高
opcache.fast_shutdown=1
;不保存文件/函数的注释
opcache.save_comments=0

实际性能对比:

下面是实际测试中没有开启opcache的数据:

[root@localhost ~]# ab -n 10000 -c 200 "http://112.126.69.14/main.php?a=Role&m=createRole"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 112.126.69.14 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software:    openresty/1.7.2.1
Server Hostname:    112.126.69.14
Server Port:      80

Document Path:     /main.php?a=Role&m=createRole
Document Length:    2 bytes

Concurrency Level:   200
Time taken for tests:  26.061 seconds
Complete requests:   10000
Failed requests:    20
  (Connect: 0, Receive: 0, Length: 20, Exceptions: 0)
Write errors:      0
Non-2xx responses:   20
Total transferred:   1713580 bytes
HTML transferred:    23520 bytes
Requests per second:  383.72 [#/sec] (mean)
Time per request:    521.216 [ms] (mean)
Time per request:    2.606 [ms] (mean, across all concurrent requests)
Transfer rate:     64.21 [Kbytes/sec] received

Connection Times (ms)
       min mean[+/-sd] median  max
Connect:    2  3  3.2   2   60
Processing:  17 461 905.0  219  16496
Waiting:    17 461 904.9  219  16496
Total:     21 464 905.0  222  16502

Percentage of the requests served within a certain time (ms)
 50%  222
 66%  271
 75%  369
 80%  412
 90%  805
 95%  1248
 98%  2597
 99%  3489
 100% 16502 (longest request)

开启之后的数据:

[root@localhost ~]# ab -n 10000 -c 200 "http://112.126.69.14/main.php?a=Role&m=createRole"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 112.126.69.14 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:    openresty/1.7.2.1
Server Hostname:    112.126.69.14
Server Port:      80

Document Path:     /main.php?a=Role&m=createRole
Document Length:    2 bytes

Concurrency Level:   200
Time taken for tests:  14.237 seconds
Complete requests:   10000
Failed requests:    0
Write errors:      0
Total transferred:   1711710 bytes
HTML transferred:    20020 bytes
Requests per second:  702.40 [#/sec] (mean)
Time per request:    284.739 [ms] (mean)
Time per request:    1.424 [ms] (mean, across all concurrent requests)
Transfer rate:     117.41 [Kbytes/sec] received

Connection Times (ms)
       min mean[+/-sd] median  max
Connect:    2  66 272.6   2  3005
Processing:   4 176 666.4   6  9026
Waiting:    4 163 642.8   6  9026
Total:     6 242 745.7   9  10028

Percentage of the requests served within a certain time (ms)
 50%   9
 66%   14
 75%   99
 80%  122
 90%  1006
 95%  1476
 98%  2853
 99%  3543
 100% 10028 (longest request)

以上所述就是本文的全部内容,希望大家能够喜欢。

PHP 相关文章推荐
PHP 编写大型网站问题集
May 07 PHP
php feof用来识别文件末尾字符的方法
Aug 01 PHP
兼容firefox,chrome的网页灰度效果
Aug 08 PHP
is_uploaded_file函数引发的不能上传文件问题
Oct 29 PHP
分享最受欢迎的5款PHP框架
Nov 27 PHP
php中使用key,value,current,next和prev函数遍历数组的方法
Mar 17 PHP
详解PHP中的Traits
Jul 29 PHP
使用PHP similar text计算两个字符串相似度
Nov 06 PHP
浅析Yii2集成富文本编辑器redactor实例教程
Apr 25 PHP
简单理解PHP的面向对象编程方式
May 17 PHP
PHP实现的登录,注册及密码修改功能分析
Nov 25 PHP
PHP二维关联数组的遍历方式(实例讲解)
Oct 18 PHP
php格式化电话号码的方法
Apr 24 #PHP
php生成年月日下载列表的方法
Apr 24 #PHP
PHP传参之传值与传址的区别
Apr 24 #PHP
php获取访问者IP地址汇总
Apr 24 #PHP
php实现的RSS生成类实例
Apr 23 #PHP
php利用事务处理转账问题
Apr 22 #PHP
ThinkPHP文件缓存类代码分享
Apr 22 #PHP
You might like
Smarty Foreach 使用说明
2010/03/23 PHP
基于PHP文件操作的详解
2013/06/05 PHP
php curl常用的5个经典例子
2017/01/20 PHP
Ajax中的JSON格式与php传输过程全面解析
2017/11/14 PHP
THINKPHP3.2使用soap连接webservice的解决方法
2017/12/13 PHP
PHP回调函数简单用法示例
2019/05/08 PHP
JS按位非(~)运算符与~~运算符的理解分析
2011/07/31 Javascript
jQuery中jqGrid分页实现代码
2011/11/04 Javascript
Html5的placeholder属性(IE兼容)实现代码
2014/08/30 Javascript
jquery不常用方法汇总
2015/07/26 Javascript
原生JS封装ajax 传json,str,excel文件上传提交表单(推荐)
2016/06/21 Javascript
Vue 过渡(动画)transition组件案例详解
2017/01/22 Javascript
JavaScript轻松创建级联函数的方法示例
2017/02/10 Javascript
基于nodejs 的多页面爬虫实例代码
2017/05/31 NodeJs
微信小程序MUI侧滑导航菜单示例(Popup弹出式,左侧滑动,右侧不动)
2019/01/23 Javascript
Linux下使用python调用top命令获得CPU利用率
2015/03/10 Python
Python实现包含min函数的栈
2016/04/29 Python
详解Python3操作Mongodb简明易懂教程
2017/05/25 Python
python读取xlsx的方法
2018/12/25 Python
使用Python画股票的K线图的方法步骤
2019/06/28 Python
Tensorflow 卷积的梯度反向传播过程
2020/02/10 Python
解决jupyter notebook显示不全出现框框或者乱码问题
2020/04/09 Python
Django模板报TemplateDoesNotExist异常(亲测可行)
2020/12/18 Python
HTML5手机端弹出遮罩菜单特效代码
2016/01/27 HTML / CSS
Kenneth Cole官网:纽约时尚优雅品牌
2016/11/14 全球购物
德国骆驼商店:ActiveFashionWorld
2017/11/18 全球购物
欧洲当代手工玻璃和瓷器的领先品牌:LSA International
2018/06/03 全球购物
环境工程毕业生自荐信
2013/11/17 职场文书
幼儿园教师获奖感言
2014/03/11 职场文书
政风行风评议整改方案
2014/09/15 职场文书
社保缴纳证明申请书
2014/11/03 职场文书
2015年会计工作总结范文
2015/05/26 职场文书
史上最全书信经典范文大全(建议收藏)
2019/07/10 职场文书
企业开发CSS命名BEM代码规范实践
2022/02/12 HTML / CSS
Win11安全功能升级:内置防网络钓鱼功能
2022/04/08 数码科技
Golang jwt身份认证
2022/04/20 Golang