3

With Symfony 5.1 and PHP 7.4, I want to add preload.php in opcache.

Symfony documentation :

During container compilation (e.g. when running the cache:clear command), Symfony generates a file called preload.php in the config/ directory with the list of classes to preload.

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

But when I execute cache:clear, I don't have preload.php file in /config/ directory.

After search on google, this site indicates :

Now, in PhpStorm, check out the var/cache/prod/ directory... here it is: App_KernelProdContainer.preload.php.

I have this file. Did I perform something wrong or is the documentation symfony not up to date ?

yivi
  • 42,438
  • 18
  • 116
  • 138
Gaylord.P
  • 1,539
  • 2
  • 24
  • 54
  • I'm not sure when config/preload.php was first added. Suppose I could check github. If you create a fresh current (5.2) project then you will get a config/preload.php file. It's just a two liner which loads the var file if it exists. Just copy the 5.2 preload.php over to your project and you should be one step further. – Cerad Dec 27 '20 at 16:49

1 Answers1

2

The file is not generated during cache generation, so you can execute cache:clear all you want and it won't be generated for you. If the documentation says so, it's wrong.

The file is copied in the corresponding flex recipe. You can check the file here.

You can check the files created by the recipe by executing:

composer symfony:recipes symfony/framework-bundle

To reinstall the recipe automatically, just execute:

composer sync-recipes symfony/framework-bundle --force
yivi
  • 42,438
  • 18
  • 116
  • 138
  • this also does nothing for me on symfony 5.1 – NDM Feb 26 '21 at 09:52
  • I don't know what you mean by "it does nothing", but it certainly works on Symfony 5.1. The recipe points specifically to that version. There must be something else missing that I can't really help you with starting from that comment, sorry. – yivi Feb 26 '21 at 09:54
  • I did the `sync-recipes --force` command, even did `git clean -df && rm -rf vendor && composer install` and the config/preload.php file is not there – NDM Feb 26 '21 at 11:57
  • I had to additionally remove `symfony.lock` seems like the `--force` option alone is not enough! – NDM Feb 26 '21 at 12:04