根据blog post,这似乎是微不足道的。显然 Symfony 从 4.4 开始生成一个预加载脚本,必须在 php.ini 中设置:
opcache.preload=/path/to/project/var/cache/prod/App_KernelProdContainer.preload.php
我在本地 Docker 环境中做了一些测试,结果如下:
不带 OPcache 的 PHP 7.3(当前)
Requests per second: 8.75 [#/sec] (mean)
Time per request: 114.402 [ms] (mean)
没有 OPcache 的 PHP 7.4
Requests per second: 11.44 [#/sec] (mean)
Time per request: 87.417 [ms] (mean)
带 OPcache 的 PHP 7.4,无预加载(Apache + modphp)
Requests per second: 30.25 [#/sec] (mean)
Time per request: 33.053 [ms]
带 OPcache 的 PHP 7.4,无预加载(nginx + php fpm)
Requests per second: 40.00 [#/sec] (mean)
不幸的是,我无法启用预加载 :( 我遇到了以下错误(在 Apache+Mod 和 Nginx+FPM 中):
double free or corruption (!prev)
child pid 17 exit signal Aborted (6), possible coredump (…)
不过,此功能看起来像 WIP。当我能够使用这个预加载的东西时,我将重新验证这个答案。总的来说,我印象深刻,仅通过从 PHP 7.3 升级到 7.4,性能就提高了 30%。