4

I know you can use with Symfony APC or XCache Class Loader. Unfortunately, in the shared server where I put my Symfony code, there is only OpCache with is activated.

Can I use Symfony with OpCache ? If yes, how and what is the code to put in my app.php please ? If not, why please ?

user849017
  • 193
  • 1
  • 3
  • 10

1 Answers1

8

You don't have to do anything in Symfony to enable opcache. You only need to make sure it's enabled in your PHP configuration (opcache_enable option).

Forget APC/XCache class loaders.

APC/XCache class loaders cache paths to classes in memory. It might not necessarily be good for your application, as it would make additional calls to apc/xcache which might be actually slower in some cases.

Optimise your composer class map.

Make sure you dump an optimised composer class map in your production environment:

composer dump-autoload --optimize

This will dump the class map to a single file. OPCache will cache this file, so in most cases it will actually be more performant then using the ApcClassLoader as there's only gonna be one call to the cache.

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
  • I always thought not using APC for class loader would cause a significant performance loss, must test without it to check the difference. – COil Jan 08 '16 at 13:38
  • 1
    As long as you optimise your composer class map and enable the opcache, the whole map should go into memory (and will be loaded only once). Related question: http://stackoverflow.com/questions/13892614/composer-vs-symfony-2-autoloader – Jakub Zalas Jan 08 '16 at 13:43
  • Seems logical, I'll give a try. Thanks Jakub. – COil Jan 08 '16 at 14:51
  • Thanks Jakub, I have a limited ssh access, I do not think I can do this in the shared server I am using. Besides, if you have any good resources to understand cache systems and mecanisms, it might be helpful to me. – user849017 Jan 09 '16 at 12:55
  • You can workaround it by running commands locally and uploading the result to the server. I suggest you change your hosting provider though. Not being able to execute commands during deployment is quite a limitation these days. – Jakub Zalas Jan 09 '16 at 15:36