2

After following the documentation, my new OPCache settings are like this:

opcache.preload_user=www-data
opcache.preload=/var/www/vhosts/.../httpdocs/.../var/cache/prod/App_KernelProdContainer.preload.php
opcache.memory_consumption=1024
opcache.interned_strings_buffer=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0

By default, inside var/cache/prod folder there is a file named srcApp_KernelProdContainer.preload.php.

After deleting /cache folder & restarting PHP-FPM, App_KernelProdContainer.preload.php is not created.

Should I rename App_KernelProdContainer.preload.php to srcApp_KernelProdContainer.preload.php or am I missing something else?

yivi
  • 42,438
  • 18
  • 116
  • 138
Khribi Wessim
  • 287
  • 2
  • 12

1 Answers1

2

No, you shouldn't add this file directly to your PHP settings, since as you discovered it makes the whole thing very brittle. You should also not rename it or anything, since it's generated automatically.

What Symfony does in latter versions is create a "preload" file.

The Symfony 4 flex recipe includes this one.

<?php

if (file_exists(dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php')) {
    require dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php';
}

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
    require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}

On Symfony 5.1+ you have something like this.

Notice that what this file requires the preload script conditionally. This way, if it doesn't exist, it won't just kill the PHP interpreter.

If you do not currently have this file; you can create it manually, or just copy it from the recipe.

Add this file to your opcache.preload settings on php.ini, not the generated preloading script directly.

yivi
  • 42,438
  • 18
  • 116
  • 138
  • Thanks for your quick answer, Symfony 4 auto generate **preload** file as you explain. So, I just removed `opcache.preload=/var/www/vhosts/.../httpdocs/.../var/cache/prod/App_KernelProdContainer.preload.php` because it's auto created inside `var\cache\prod`. But I didn't understand your last added line: _Add this file to your opcache.preload settings on php.ini, not the generated preloading script directly_ – Khribi Wessim Sep 16 '21 at 20:04
  • 1
    The `opcache.preload` option should point to the `preload.php` file. `opcache.preload="/path/to/preload.php`. – yivi Sep 16 '21 at 20:16