Opcache improves PHP performance by storing PHP script precompiled bytecode in shared memory, and the benefit of storing precompiled bytecode is to eliminate the overhead of loading and parsing PHP scripts every time.
One, php.ini configuration Opchche Example
[opcache]zend_extension=opcache.so; switch opens Opcache.enable=1opcache.enable_cli=1; shared memory size, as appropriate, units megabytesopcache.memory_consumption=256 ;interned string Memory Size, also adjustable opcache.interned_strings_buffer=8; The maximum number of cached files, the hit rate is less than 100% , can try to improve this value opcache.max_accelerated_ files=4000;60s Check for file update opcache.revalidate_freq=60; Open Quick close, Open this at php request shutdown time will increase the speed of opcache.fast_shutdown=1, do not save the file/function comment opcache.save_comments=0 ; whether quickly close, The speed of reclaiming memory when Php request shutdown is turned on will increase opcache.fast_shutdown=1. Part configuration parameter Description opcache.revalidate_freq This configuration option is used to set the cache expiration time, if set to 0, each request, will check whether the file is modified, very resource-intensive, so if you do not need to use Opcache, opcache.enable directly set to 0. opcache.validate_timestamps is configured to 1 o'clock, the update code is checked against the values set by the Revalidate_freq, set to 0 o'clock, and never checked. When you need to update a large number of code at once, you can set to 0, upload all completed, and then set to 1. Avoid uploading code to cause system instability. The real value of opcache.max_accelerated_files is in the { 223, 463, 983, 1979, 3907 of the mass number set, 7963, 16229, The first prime number found in;32531, 65407, 130987 } that is larger than the set value. You can run find . -type f -print | grep php | wc -l This command to quickly calculate the number of PHP files in your code base.
Recommended in development mode, directly disabling the Opcache extension is better
Opcache.revalidate_freq=0
Opcache.validate_timestamps=1
opcache.max_accelerated_files=3000
opcache.memory_consumption=192
Opcache.interned_strings_buffer=16
Opcache.fast_shutdown=1
Multi-machine cluster mode or code update frequently recommended, can take into account performance, convenient code update
opcache.revalidate_freq=300
Opcache.validate_timestamps=1
opcache.max_accelerated_files=7963
opcache.memory_consumption=192
Opcache.interned_strings_buffer=16
Opcache.fast_shutdown=1
Stable Project recommendation, best performance
Opcache.revalidate_freq=0
Opcache.validate_timestamps=0
opcache.max_accelerated_files=7963
opcache.memory_consumption=192
Opcache.interned_strings_buffer=16
Opcache.fast_shutdown=1
PHP Open Opcache