一,測試環境:
PHP 8.3.9
Laravel Framework 11.15.0
介面沒訪問資料,只是從redis取資料
測試前已開啟opcache+jit
二,未開啟optimize時訪問10次
測試前先執行4個clear,避免有之前做的cache
root@lhdpc:/data/api# php artisan route:clear
INFO Route cache cleared successfully.
root@lhdpc:/data/api# php artisan config:clear
INFO Configuration cache cleared successfully.
root@lhdpc:/data/api# php artisan view:clear
INFO Compiled views cleared successfully.
root@lhdpc:/data/api# php artisan event:clear
INFO Cached events cleared successfully.
訪問10次的資料,單位:毫秒
41
24
50
37
24
30
32
31
28
33
三,開啟optimize後訪問10次
開啟optimize
root@lhdpc:/data/api# php artisan optimize
INFO Caching framework bootstrap, configuration, and metadata.
config .............................................................................................................................. 26.14ms DONE
events ............................................................................................................................... 3.92ms DONE
routes .............................................................................................................................. 63.15ms DONE
views ............................................................................................................................... 47.48ms DONE
訪問10次的資料,單位:毫秒
28
24
17
25
23
25
22
12
29
27
顯然有約10ms左右的提升,
但這個提升有一點的程式碼,
釋出程式碼和修改配置後需要執行一次最佳化,
程式碼的編寫需要規避直接呼叫env()函式