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 相关文章推荐
一个没有MYSQL数据库支持的简易留言本的编写
Oct 09 PHP
PHP校验ISBN码的函数代码
Jan 17 PHP
php DOS攻击实现代码(附如何防范)
May 29 PHP
解决FastCGI 进程超过了配置的活动超时时限的问题
Jul 03 PHP
php判断文件夹是否存在不存在则创建
Apr 09 PHP
php筛选不存在的图片资源
Apr 28 PHP
php将数组存储为文本文件方法汇总
Oct 28 PHP
PHP下载文件的函数实例代码
May 18 PHP
Laravel接收前端ajax传来的数据的实例代码
Jul 20 PHP
PHP实现的堆排序算法详解
Aug 17 PHP
对php 判断http还是https,以及获得当前url的方法详解
Jan 15 PHP
php命名空间设计思想、用法与缺点分析
Jul 17 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/07/08 PHP
PHP新手上路(三)
2006/10/09 PHP
php 微信开发获取用户信息如何实现
2016/12/13 PHP
thinkphp框架无限级栏目的排序功能实现方法示例
2020/03/29 PHP
javascript实现的动态文字变换
2007/07/28 Javascript
jQuery EasyUI API 中文文档 - ComboBox组合框
2011/10/07 Javascript
jQuery基础框架浅入剖析
2012/12/27 Javascript
ExtJS判断IE浏览器类型的方法
2014/02/10 Javascript
javascript event在FF和IE的兼容传参心得(绝对好用)
2014/07/10 Javascript
JS回调函数的应用简单实例
2014/09/17 Javascript
JavaScript sub方法入门实例(把字符串显示为下标)
2014/10/17 Javascript
JavaScript函数的一些注意要点小结及js匿名函数
2015/11/10 Javascript
JavaScript实现图片自动加载的瀑布流效果
2016/04/11 Javascript
AngularJS中isolate scope的用法分析
2016/11/22 Javascript
详解vue-router 2.0 常用基础知识点之导航钩子
2017/05/10 Javascript
Vue.js与 ASP.NET Core 服务端渲染功能整合
2017/11/16 Javascript
详解为Bootstrap Modal添加拖拽的方法
2018/01/05 Javascript
vue路由组件按需加载的几种方法小结
2018/07/12 Javascript
google广告之另类js调用实现代码
2020/08/22 Javascript
Python中的__SLOTS__属性使用示例
2015/02/18 Python
在CentOS上配置Nginx+Gunicorn+Python+Flask环境的教程
2016/06/07 Python
python 3.74 运行import numpy as np 报错lib\site-packages\numpy\__init__.py
2019/10/06 Python
Python元组 tuple的概念与基本操作详解【定义、创建、访问、计数、推导式等】
2019/10/30 Python
pyCharm 设置调试输出窗口中文显示方式(字符码转换)
2020/06/09 Python
使用TensorBoard进行超参数优化的实现
2020/07/06 Python
PyCharm 2020.2下配置Anaconda环境的方法步骤
2020/09/23 Python
Html5 APP中监听返回事件处理的方法示例
2018/03/15 HTML / CSS
家用个人磨皮机:Trophy Skin
2017/03/30 全球购物
柏林通行证:Berlin Pass
2018/04/11 全球购物
英国领先的体验日提供商:Buyagift
2019/04/19 全球购物
LINUX下线程,GDI类的解释
2016/12/14 面试题
服务整改报告
2014/11/06 职场文书
中秋节寄语2015
2015/03/24 职场文书
义卖募捐活动总结
2015/05/09 职场文书
简单聊聊TypeScript只读修饰符
2022/04/06 Javascript
TypeScript 内置高级类型编程示例
2022/09/23 Javascript