网络编程 
首页 > 网络编程 > 浏览文章

PHP开启opcache提升代码性能

(编辑:jimmy 日期: 2024/10/15 浏览:3 次 )

配置指令如下:

[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"
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"htmlcode">
[root@localhost ~]# ab -n 10000 -c 200 "http://112.126.69.14/main.php"
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)

以上所述就是本文的全部内容,希望大家能够喜欢。

上一篇:如何使用jQuery+PHP+MySQL来实现一个在线测试项目
下一篇:php格式化电话号码的方法
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?