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写的采集程序
Mar 16 PHP
php xml文件操作实现代码(二)
Mar 20 PHP
php中Session的生成机制、回收机制和存储机制探究
Aug 19 PHP
php使用wordwrap格式化文本段落的方法
Mar 17 PHP
在WordPress的文章编辑器中设置默认内容的方法
Dec 29 PHP
php注册登录系统简化版
Dec 28 PHP
Yii2 ActiveRecord多表关联及多表关联搜索的实现
Jun 30 PHP
Yii2中添加全局函数的方法分析
May 04 PHP
PHP自定义函数实现数组比较功能示例
Oct 19 PHP
设定php简写功能的方法
Nov 28 PHP
PHP配合fiddler抓包抓取微信指数小程序数据的实现方法分析
Jan 02 PHP
php 多进程编程父进程的阻塞与非阻塞实例分析
Feb 22 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
第十一节--重载
2006/11/16 PHP
Bo-Blog专用的给Windows服务器的IIS Rewrite程序
2007/08/26 PHP
php获取post中的json数据的实现方法
2011/06/08 PHP
PHP开发者常犯的10个MySQL错误更正剖析
2012/01/30 PHP
PHP获取不了React Native Fecth参数的解决办法
2016/08/26 PHP
PHP类和对象相关系统函数与运算符小结
2016/09/28 PHP
dropdownlist之间的互相联动实现(显示与隐藏)
2009/11/24 Javascript
jQuery中将函数赋值给变量的调用方法
2012/03/23 Javascript
Jquery刷新页面背景图片随机变换的实现方法
2013/03/15 Javascript
jQuery 获取/设置/删除DOM元素的属性以a元素为例
2014/05/23 Javascript
JavaScript判断一个字符串是否包含指定子字符串的方法
2015/03/18 Javascript
javascript创建函数的20种方式汇总
2015/06/23 Javascript
基于JavaScript实现鼠标悬浮弹出跟随鼠标移动的带箭头的信息层
2016/01/18 Javascript
基于javascript实现表格的简单操作
2016/05/21 Javascript
非常酷炫的Bootstrap图片轮播动画
2016/05/27 Javascript
jQuery弹出层插件popShow(改进版)用法示例
2017/01/23 Javascript
vue实现学生录入系统之添加删除功能
2018/07/11 Javascript
JS实现select选中option触发事件操作示例
2018/07/13 Javascript
JS实现星星海特效
2019/12/24 Javascript
解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”
2020/02/12 Javascript
JS如何把字符串转换成json
2020/02/21 Javascript
Python实现统计代码行的方法分析
2017/07/12 Python
Python中如何优雅的合并两个字典(dict)方法示例
2017/08/09 Python
Python入门之三角函数tan()函数实例详解
2017/11/08 Python
Python 查看文件的读写权限方法
2018/01/23 Python
Python统计纯文本文件中英文单词出现个数的方法总结【测试可用】
2018/07/25 Python
python+selenium实现自动化百度搜索关键词
2019/06/03 Python
Pytorch 使用opnecv读入图像由HWC转为BCHW格式方式
2020/06/02 Python
10种CSS3实现的loading动画,挑一个走吧?
2020/11/16 HTML / CSS
继电保护工岗位职责
2014/01/05 职场文书
优秀技术工人先进材料
2014/02/17 职场文书
语文课外活动总结
2014/08/27 职场文书
入党积极分子对十八届四中全会期盼的思想汇报
2014/10/17 职场文书
投标售后服务承诺书
2015/04/29 职场文书
公司转让协议书
2016/03/19 职场文书
不想升级Win11?教你彻底锁定老版Windows系统的方法(附下载地址)
2022/09/23 数码科技