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错误提示failed to open stream: HTTP request failed!的完美解决方法
Jun 06 PHP
php类常量的使用详解
Jun 08 PHP
php生成N个不重复的随机数实例
Nov 12 PHP
从零开始学YII2框架(三)扩展插件yii2-gird
Aug 20 PHP
PHP实现抓取HTTPS内容
Dec 01 PHP
PHP实现图片自动清理的方法
Jul 08 PHP
PHP实现GIF图片验证码
Nov 04 PHP
PHP实现时间比较和时间差计算的方法示例
Jul 24 PHP
PHP7扩展开发教程之Hello World实现方法示例
Aug 03 PHP
CMSPRESS 10行代码搞定 PHP无限级分类2
Mar 30 PHP
laravel 自定义常量的两种方案
Oct 14 PHP
PHP 实现 JSON 数据的编码和解码操作详解
Apr 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
IIS6+PHP5+MySQL5+Zend Optimizer+phpMyAdmin安装配置图文教程 2009年
2009/06/08 PHP
PHP应用跨时区功能的实现方法
2019/03/21 PHP
laravel框架使用极光推送消息操作示例
2020/02/15 PHP
jQuery EasyUI API 中文文档 DateTimeBox日期时间框
2011/10/16 Javascript
JavaScript版DateAdd和DateDiff函数代码
2012/03/01 Javascript
jQuery中nextAll()方法用法实例
2015/01/07 Javascript
概述jQuery中的ajax方法
2016/12/16 Javascript
javascript中的深复制详解及实例分析
2016/12/29 Javascript
详解AngularJS通过ocLazyLoad实现动态(懒)加载模块和依赖
2017/03/01 Javascript
JS条形码(一维码)插件JsBarcode用法详解【编码类型、参数、属性】
2017/04/19 Javascript
微信小程序 navbar实例详解
2017/05/11 Javascript
vue2.0的虚拟DOM渲染思路分析
2018/08/09 Javascript
40行代码把Vue3的响应式集成进React做状态管理
2020/05/20 Javascript
使用Vue-cli 中为单独页面设置背景图片铺满全屏
2020/07/17 Javascript
Javascript执行上下文顺序的深入讲解
2020/11/04 Javascript
[47:12]TFT vs Secret Supermajor小组赛C组 BO3 第三场 6.3
2018/06/04 DOTA
python使用wxPython打开并播放wav文件的方法
2015/04/24 Python
Python中使用装饰器来优化尾递归的示例
2016/06/18 Python
Python3安装Scrapy的方法步骤
2017/11/23 Python
Python判断字符串是否为字母或者数字(浮点数)的多种方法
2018/08/03 Python
Python访问MongoDB,并且转换成Dataframe的方法
2018/10/15 Python
Python 保持登录状态进行接口测试的方法示例
2019/08/06 Python
如何利用python web框架做文件流下载的实现示例
2020/06/02 Python
python实现批处理文件
2020/07/28 Python
医药工作岗位求职信分享
2013/12/31 职场文书
医药专业应届毕业生求职信范文
2014/01/01 职场文书
一个大学生十年的职业规划
2014/01/17 职场文书
小学教师培训方案
2014/06/09 职场文书
销售类求职信
2014/06/13 职场文书
教师批评与自我批评总结
2014/10/16 职场文书
2015年学校安全工作总结
2015/04/22 职场文书
2015年保洁员工作总结
2015/05/04 职场文书
爸爸的三轮车观后感
2015/06/16 职场文书
法人身份证明书
2015/06/18 职场文书
大队委员竞选稿
2015/11/20 职场文书
高三英语教学反思
2016/03/03 职场文书