How can I enable opcache preloading in PHP 7.4?

emix picture emix · Dec 12, 2019 · Viewed 8.9k times · Source

I'd like to enable opcache preloading (RFC) on my production servers in PHP 7.4.

I'm using Symfony 4 if it changes anything.

Answer

emix picture emix · Dec 14, 2019

According to the blog post this appears to be trivial. Apparently Symfony since 4.4 generates a preload script which has to be set in the php.ini:

opcache.preload=/path/to/project/var/cache/prod/App_KernelProdContainer.preload.php

I did some tests in my local Docker environment and this is how it went:

PHP 7.3 without OPcache (current)

Requests per second:    8.75 [#/sec] (mean)
Time per request:       114.402 [ms] (mean)

PHP 7.4 without OPcache

Requests per second:    11.44 [#/sec] (mean)
Time per request:       87.417 [ms] (mean)

PHP 7.4 with OPcache, without preloading (Apache + modphp)

Requests per second:    30.25 [#/sec] (mean)
Time per request:       33.053 [ms]

PHP 7.4 with OPcache, without preloading (nginx + php fpm)

Requests per second:    40.00 [#/sec] (mean)

Unfortunately I was not able to enable the preloading :( I encountered following errors (in both Apache+Mod and Nginx+FPM):

double free or corruption (!prev)
child pid 17 exit signal Aborted (6), possible coredump (…)

This feature looks like a WIP though. I'm going to revalidate this answer when I'm able to use this preloading thing. In overall I'm quite impressed, +30% performance just by upgrading from PHP 7.3 to 7.4.