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新手上路(二)
Oct 09 PHP
一篇入门的php Class 文章
Apr 04 PHP
基于PHP 面向对象之成员方法详解
May 04 PHP
php读取纯真ip数据库使用示例
Jan 26 PHP
php调用google接口生成二维码示例
Apr 28 PHP
PHP基于CURL进行POST数据上传实例
Nov 10 PHP
php中array_column函数简单实现方法
Jul 11 PHP
Yii2实现同时搜索多个字段的方法
Aug 10 PHP
ecshop添加菜单及权限分配问题
Nov 21 PHP
PHP使用ActiveMQ实现消息队列的方法详解
May 31 PHP
PHP getID3类的使用方法学习笔记【附getID3源码下载】
Oct 18 PHP
实例化php类时传参的方法分析
Jun 05 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
利用PHP创建动态图像
2006/10/09 PHP
PHP中利用substr_replace将指定两位置之间的字符替换为*号
2011/01/27 PHP
PHP采集腾讯微博的实现代码
2012/01/19 PHP
php字符编码转换之gb2312转为utf8
2013/10/28 PHP
ThinkPHP3.1查询语言详解
2014/06/19 PHP
php使用CutyCapt实现网页截图保存的方法
2016/10/03 PHP
PHP符合PSR编程规范的实例分享
2016/12/21 PHP
JavaScript脚本性能优化注意事项
2008/11/18 Javascript
JS获取父节点方法
2009/08/20 Javascript
深入解析JavaScript中函数的Currying柯里化
2016/03/19 Javascript
BootStrap.css 在手机端滑动时右侧出现空白的原因及解决办法
2016/06/07 Javascript
jquery表格datatables实例解析 直接加载和延迟加载
2016/08/12 Javascript
jquery-mobile基础属性与用法详解
2016/11/23 Javascript
jQuery查找dom的几种方法效率详解
2017/05/17 jQuery
JavaScript函数中的this四种绑定形式
2017/08/15 Javascript
JavaScript代码执行的先后顺序问题
2017/10/29 Javascript
vue用Object.defineProperty手写一个简单的双向绑定的示例
2018/07/09 Javascript
Vue中props的详解
2019/05/16 Javascript
Vue.js+cube-ui(Scroll组件)实现类似头条效果的横向滚动导航条
2019/06/24 Javascript
[02:30]DOTA2放量测试专访海涛:呼吁保护新手玩家
2013/08/26 DOTA
python解决字典中的值是列表问题的方法
2013/03/04 Python
python网络编程学习笔记(10):webpy框架
2014/06/09 Python
Python中优化NumPy包使用性能的教程
2015/04/23 Python
几个适合python初学者的简单小程序,看完受益匪浅!(推荐)
2019/04/16 Python
python发qq消息轰炸虐狗好友思路详解(完整代码)
2020/02/15 Python
Python学习之路之pycharm的第一个项目搭建过程
2020/06/18 Python
Python3 ffmpeg视频转换工具使用方法解析
2020/08/10 Python
python中用ggplot绘制画图实例讲解
2021/01/26 Python
html5 datalist标签使用示例(自动完成组件)
2014/05/04 HTML / CSS
发现世界上最好的珠宝设计师:JewelStreet
2017/12/17 全球购物
英国领先的电子、技术和办公用品购物网站:Ebuyer
2018/04/04 全球购物
我的梦想演讲稿
2014/04/30 职场文书
个人对照检查材料思想汇报
2014/09/26 职场文书
初三语文教学计划
2015/01/22 职场文书
vue完美实现el-table列宽自适应
2021/05/08 Vue.js
HTML中实现音乐或视频自动播放案例详解
2022/05/30 HTML / CSS