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 相关文章推荐
WIN98下Apache1.3.14+PHP4.0.4的安装
Oct 09 PHP
下载文件的点击数回填
Oct 09 PHP
php中根据某年第几天计算出日期年月日的代码
Feb 24 PHP
浅谈php中mysql与mysqli的区别分析
Jun 10 PHP
php自动加载autoload机制示例分享
Feb 20 PHP
Windows下的PHP安装文件线程安全和非线程安全的区别
Apr 23 PHP
ThinkPHP中自定义目录结构的设置方法
Aug 15 PHP
配置eAccelerator和XCache扩展来加速PHP程序的执行
Dec 22 PHP
深入浅析yii2-gii自定义模板的方法
Apr 26 PHP
phpmailer绑定邮箱的实现方法
Dec 01 PHP
PHP实现二维数组根据key进行排序的方法
Dec 30 PHP
CodeIgniter框架基本增删改查操作示例
Mar 23 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
探讨fckeditor在Php中的配置详解
2013/06/08 PHP
php 修改上传文件大小限制实例详解
2016/10/23 PHP
PHP遍历目录文件的常用方法小结
2017/02/03 PHP
Smarty模板类内部原理实例分析
2019/07/03 PHP
Javascript中的数学函数
2007/04/04 Javascript
基于jQuery的左右滚动实现代码
2010/12/03 Javascript
jQuery Ajax请求状态管理器打包
2012/05/03 Javascript
js自定义事件及事件交互原理概述(一)
2013/02/01 Javascript
node.js入门教程
2014/06/01 Javascript
基于jQuery创建鼠标悬停效果的方法
2015/03/07 Javascript
Hallo.js基于jQuery UI所见即所得的Web编辑器
2016/01/26 Javascript
jquery 实现滚动条下拉时无限加载的简单实例
2016/06/01 Javascript
Javascript点击其他任意地方隐藏关闭DIV实例
2016/06/21 Javascript
Bootstrap选项卡与Masonry插件的完美结合
2016/07/06 Javascript
Node.js连接postgreSQL并进行数据操作
2016/12/18 Javascript
JavaScript限制在客户区可见范围的拖拽(解决scrollLeft和scrollTop的问题)(2)
2017/05/17 Javascript
微信小程序 下拉刷新及上拉加载原理解析
2019/11/06 Javascript
[50:12]EG vs Fnatic 2018国际邀请赛小组赛BO2 第二场 8.19
2018/08/21 DOTA
简析Python的闭包和装饰器
2016/02/26 Python
python操作字典类型的常用方法(推荐)
2016/05/16 Python
python 接口返回的json字符串实例
2018/03/27 Python
python使用Matplotlib画条形图
2020/03/25 Python
Python实现按逗号分隔列表的方法
2018/10/23 Python
pytorch 实现cross entropy损失函数计算方式
2020/01/02 Python
python设置中文界面实例方法
2020/10/27 Python
解决selenium+Headless Chrome实现不弹出浏览器自动化登录的问题
2021/01/09 Python
html5跨域通讯之postMessage的用法总结
2013/11/07 HTML / CSS
奥斯汀独木舟和皮划艇:Austin Canoe & Kayak
2018/05/22 全球购物
类的核心特性有哪些
2014/01/01 面试题
拓展培训心得体会
2014/01/04 职场文书
工程力学专业自荐信范文
2014/03/17 职场文书
保证书范文大全
2014/04/28 职场文书
学校爱心捐款倡议书
2014/05/13 职场文书
沙滩主题婚礼活动策划方案
2014/09/15 职场文书
2014年护士个人工作总结
2014/11/11 职场文书
一篇文章学会Vue中间件管道
2021/06/20 Vue.js