I'm working with a Magento 2 stack, I'm reusing some of my Magento 1 OpCache configuration. I've already learned that now we need to enable comments but I'm pretty sure that other values can be improved, so here is my current configuration:

opcache.max_accelerated_files=65406 // thanks Mage2.Pro!

NOTE: I will edit the configuration block in the question (while opened) with all good answers in order to make it useful for everyone, and avoid repeated suggestions too, if there is any problem about that or represents a violation to the site rules, just let me know.

  • Why not enable the opcache for CLI?
    – MagePsycho
    Sep 14, 2017 at 19:55
  • As stated in official magento2 docs you should make sure save_comments value is set to 1. "opcache.save_comments=1"
    – karpa
    May 26, 2020 at 0:20

3 Answers 3


opcache.max_accelerated_files=16000 is definitely low for Magento 2.
find . -type f -print | xargs grep "<?php" | wc -l gives me 30736 for my Magento 2 installation (with a code generated in the var/generation folder and with some external extensions installed).
I recommend set opcache.max_accelerated_files to 65406 if your server has a single Magento 2 installation and has not other PHP sites.
If you have multiple PHP sites on the server then consider the value 130986.


I would also recommend to include the following settings which were added in php7 I believe

; Allows calling OPcache API functions only from PHP scripts which path is
; started from specified string. The default "" means no restriction

; Mapping base of shared memory segments (for Windows only). All the PHP
; processes have to map shared memory into the same address space. This
; directive allows to manually fix the "Unable to reattach to base address"
; errors.

; Enables and sets the second level cache directory.
; It should improve performance when SHM memory is full, at server restart or
; SHM reset. The default "" disables file based caching.

; Enables or disables opcode caching in shared memory.

; Enables or disables checksum validation when script loaded from file cache.

; Implies opcache.file_cache_only=1 for a certain process that failed to
; reattach to the shared memory (for Windows only). Explicitly enabled file
; cache is required.

; Enables or disables copying of PHP code (text segment) into HUGE PAGES.
; This should improve performance, but requires appropriate OS configuration.

Settings from Magento 2.4 documentation:


opcache.memory_consumption without MB!

It might be worth increasing the value for Magento Commerce Cloud Pro:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.