0

In Symfony2, in the extension file of a bundle, it is possible to call:

$this->addClassesToCompile([class1, ....])

This adds the given files to the cached file classes.php => this can improve performances if we put here the most used classes, because the PHP process only have to find and process 1 file insteaf many.

But with the 5.6 version of PHP, there is OPcache that can also cache files and also precompile them. So I guess that the Symfony part isn't necessary anymore?

Rolintocour
  • 2,934
  • 4
  • 32
  • 63

1 Answers1

2

By using a byte code cache PHP itself will cache the classes separately from the bootstrapped cache file. APC is already used for years to achieve this. PHP5.5 included the OPcache by default to do handle the opcache. Where APC also enabled users to easily add cache items itself, the OPcache is not available for users.

Because of that, APCu was split from the original APC library so the traditional user caching becomes available for > PHP5.4. More info about Symfony performance can be found in The Book's performance chapter.

To answer your question about the Symfony bootstrap: If you use both the bootstrap caching and a bytecode cache, then adding files to the bootstrap will result into a bigger bytecode cache file. If your application has classes (like kernel.request listeners) that are used in every request, adding them to the bootstrap makes sense. Otherwise it will only add overhead to, and will it marginally slow down all other requests.

Rvanlaak
  • 2,971
  • 20
  • 40