9

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]
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=256
opcache.interned_strings_buffer=12
opcache.max_accelerated_files=65406 // thanks Mage2.Pro!
;opcache.max_wasted_percentage=5
;opcache.use_cwd=1
opcache.validate_timestamps=0
;opcache.revalidate_freq=2
;opcache.revalidate_path=0
;opcache.save_comments=0
;opcache.load_comments=0
opcache.fast_shutdown=1
opcache.enable_file_override=1
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
;opcache.blacklist_filename=
;opcache.max_file_size=0
;opcache.consistency_checks=0
;opcache.force_restart_timeout=180
opcache.error_log=/var/log/php5/php5-opcache.error.log
opcache.log_verbosity_level=3
;opcache.preferred_memory_model=
;opcache.protect_memory=0

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 '17 at 19:55
11

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.

0

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
;opcache.restrict_api=

; 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.
;opcache.mmap_base=

; 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.
;opcache.file_cache=

; Enables or disables opcode caching in shared memory.
;opcache.file_cache_only=0

; Enables or disables checksum validation when script loaded from file cache.
;opcache.file_cache_consistency_checks=1

; 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.
;opcache.file_cache_fallback=1

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

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.