如何在PHP 7.4中启用opcache预加载?


Answers:


4

首先,您应该添加:

opcache.preload=/path/to/project/preload.php

给你 php.ini

然后,在您的PHP脚本中,您应该传递opcache_compile_file($file);要预加载的每个文件。


4

根据博客文章,这似乎是微不足道的。从4.4开始,显然Symfony会生成一个预加载脚本,该脚本必须在中设置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。当我能够使用此预加载功能时,我将重新验证该答案。在总的来说,我很深刻的印象,+ 30%的性能仅仅通过升级从PHP 7.37.4

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.