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扩展开发经验分享
Sep 06 PHP
深入apache host的配置详解
Jun 09 PHP
PHP采用自定义函数实现遍历目录下所有文件的方法
Aug 19 PHP
php中使用PHPExcel读写excel(xls)文件的方法
Sep 15 PHP
codeigniter发送邮件并打印调试信息的方法
Mar 21 PHP
两种php实现图片上传的方法
Jan 22 PHP
Zend Framework连接Mysql数据库实例分析
Mar 19 PHP
php实现的XML操作(读取)封装类完整实例
Feb 23 PHP
利用PHP获取汉字首字母并且分组排序详解
Oct 22 PHP
PHP使用curl_multi_select解决curl_multi网页假死问题的方法
Aug 15 PHP
php获取用户真实IP和防刷机制的实例代码
Nov 28 PHP
解决在laravel中leftjoin带条件查询没有返回右表为NULL的问题
Oct 15 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 中的str_replace 函数总结
2007/04/27 PHP
fleaphp crud操作之find函数的使用方法
2011/04/23 PHP
有关PHP中MVC的开发经验分享
2012/05/17 PHP
PHP中比较两个字符串找出第一个不同字符位置例子
2014/04/08 PHP
PHP多文件上传实例
2015/07/09 PHP
用按钮控制iframe显示的网页实现方法
2013/02/04 Javascript
js+html5获取用户地理位置信息并在Google地图上显示的方法
2015/06/05 Javascript
基于jquery插件编写countdown计时器
2016/06/12 Javascript
详谈Angular路由与Nodejs路由的区别
2017/03/05 NodeJs
vue引入新版 vue-awesome-swiper插件填坑问题
2018/01/25 Javascript
理解 JavaScript EventEmitter
2018/03/29 Javascript
详解vue-cli@2.x项目迁移日志
2019/06/06 Javascript
Vue.js实现大转盘抽奖总结及实现思路
2019/10/09 Javascript
Angular6项目打包优化的实现方法
2019/12/15 Javascript
vue实现分页的三种效果
2020/06/23 Javascript
Vue如何将页面导出成PDF文件
2020/08/17 Javascript
在webstorm中配置less的方法详解
2020/09/25 Javascript
python批量生成本地ip地址的方法
2015/03/23 Python
Python判断某个用户对某个文件的权限
2016/10/13 Python
python3爬取数据至mysql的方法
2018/06/26 Python
python简单验证码识别的实现方法
2019/05/10 Python
详解Python3之数据指纹MD5校验与对比
2019/06/11 Python
python GUI库图形界面开发之PyQt5计数器控件QSpinBox详细使用方法与实例
2020/02/28 Python
使用pth文件添加Python环境变量方式
2020/05/26 Python
IntelliJ 中配置 Anaconda的过程图解
2020/06/01 Python
哪种Python框架适合你?简单介绍几种主流Python框架
2020/08/04 Python
python 实现表情识别
2020/11/21 Python
对CSS3选择器的研究(详解)
2016/09/16 HTML / CSS
全球性的女装店:storets
2019/06/12 全球购物
最新教师自我评价分享
2013/11/12 职场文书
影视艺术学院毕业生自荐信
2013/11/13 职场文书
《伯牙绝弦》教学反思
2014/03/02 职场文书
2014年扶贫工作总结
2014/11/18 职场文书
长江七号观后感
2015/06/11 职场文书
2015年工会工作总结范文
2015/07/23 职场文书
logback 实现给变量指定默认值
2021/08/30 Java/Android