PHP开启opcache提升代码性能
作者:hebedich 时间:2023-06-17 04:39:55
配置指令如下:
[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,开启opcache
0
投稿
猜你喜欢
教你用Python实现一个轮盘抽奖小游戏
2021-11-04 23:49:03
配置python的编程环境之Anaconda + VSCode的教程
2021-09-05 14:12:18
Javascript 注册事件浅析
2024-04-28 10:20:22
Python爬虫天气预报实例详解(小白入门)
2023-03-23 16:05:48
基于Python编写简易文字语音转换器
2023-12-28 19:24:54
python随机模块random的22种函数(小结)
2022-08-11 18:09:03
python不同版本的_new_不同点总结
2023-09-21 15:36:45
重命名批处理python脚本
2021-04-27 22:56:38
Python及PyCharm下载与安装教程
2022-10-04 08:19:54
如何把外网python虚拟环境迁移到内网
2021-12-28 14:08:13
asp 隐藏并修改文件的最后修改时间
2011-03-29 10:34:00
mysql主从服务器配置特殊问题
2011-01-04 19:56:00
MySQL 开窗函数
2024-01-15 11:06:24
基于javascript实现tab选项卡切换特效调试笔记
2024-06-12 13:48:02
关于使用pyqt弹出消息提示框的问题
2022-02-15 22:22:01
python基础知识小结之集合
2021-07-14 23:34:54
python函数不定长参数使用方法解析
2022-07-05 23:47:20
安装mysql8.0.11及修改root密码、连接navicat for mysql的思路详解
2024-01-17 14:11:18
python调用私有属性的方法总结
2023-09-06 03:16:18
Python 创建子进程模块subprocess详解
2022-02-21 06:47:39