laravel11: 开启optimize和不开启optimize的区别有多大?

一,测试环境:

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()函数

 

posted @ 2024-10-16 14:08  刘宏缔的架构森林  阅读(73)  评论(0编辑  收藏  举报