本篇內容主要講解“PHP怎么開啟opcache提升代碼性能”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“PHP怎么開啟opcache提升代碼性能”吧!
目前創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網站建設、域名、網頁空間、網站托管維護、企業(yè)網站設計、麻章網站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。配置指令如下:
[opcache] zend_extension=opcache.so opcache.enable_cli=1 ;共享內存大小, 這個根據(jù)你們的需求可調 opcache.memory_consumption=256 ;interned string的內存大小, 也可調 opcache.interned_strings_buffer=8 ;較大緩存的文件數(shù)目 opcache.max_accelerated_files=4000 ;60s檢查一次文件更新 opcache.revalidate_freq=60 ;打開快速關閉, 打開這個在PHP Request Shutdown的時候 會收內存的速度會提高 opcache.fast_shutdown=1 ;不保存文件/函數(shù)的注釋 opcache.save_comments=0
實際性能對比:
下面是實際測試中沒有開啟opcache的數(shù)據(jù):
[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, /tupian/20230522/ Licensed to The Apache Software Foundation, /tupian/20230522/ 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)
開啟之后的數(shù)據(jù):
[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, /tupian/20230522/ Licensed to The Apache Software Foundation, /tupian/20230522/ 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提升代碼性能”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!