Excellent software and practical tutorials
You understandopcache.memory_consumption", but who knows how to set it? Is 32 too much? Or too little? Who knows? There is nothing on the search engine, so just use the default setting. The default setting does not enable the best cache performance of Zend OpCache.
Correct use of Zend OpCache can improve PHP access speed and optimize PHP performance. How to set Zend OpCache after enabling it? Next, let's talk about some parameters that need to be adjusted.
The first thing to say is where to modify the configuration parameters of Zend OpCache, of course, in your php.ini file. Find [OpCache] and set it under the [OpCache] container.
opcache.revalidate_freq : Time (in seconds) after which the code cache expires and checks if the code has changed. 0 means it will check your PHP code on every request (this adds a lot of stat syscalls). Set this to 0 in your development environment.
opcache.validate_timestamps: With this option enabled, PHP will check file timestamps against your opcache.revalidate_freq value. If this option is disabled, opcache.revaliate_freq will be ignored and no PHP files will be checked for updated code. Therefore, if you modify your code, the changes will not actually take effect until you restart or reload the PHP server. Comment out opcache.validate_timestamps in your development environment.
opcache.max_accelerated_files: controls how many PHP files can be kept in memory at a time. It is most important that your website directory has less PHP files than what is set. For example, the PHP files under the website directory have about 6000 files, so I use the prime number 7963 for maxacceleratedfiles.
You can quickly count the number of files in your codebase by running: Go to your website directory and execute the following command.
find . -type f -print | grep php | wc -l
opcache.memory_consumption: The default value is 64MB, set it to 256MB for when you have a lot of code. You can use the function opcachegetstatus() to tell how much memory opcache is consuming and if you need to increase it.
opcache.interned_strings_buffer: PHP uses a technique called string interning to improve performance. For example: if you use the string "foobar" 1000 times in your code, PHP will store 1 immutable variable internally for that string and one pointer to another string used 999 times. Instead of having a pool of these immutable strings for each single php-fpm process, this setting shares them across all php-fpm processes. It saves memory and improves performance, especially in large applications. The value is set in megabytes, so for 16MB, set it to "16". The default value is 4MB.
opcache.revalidate_freq=0 opcache.validate_timestamps=0 opcache.max_accelerated_files=7963 opcache.memory_consumption=256 opcache.interned_strings_buffer=16