PHP OPcache Configuration Guide

There are two methods to configure opcache in PHP.

  1. Configure via php.ini: Add the following configuration options in the php.ini file to configure the settings for opcache.
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1

These configuration parameters can be adjusted according to the actual needs.

  1. Configure using opcache functions: Use opcache-related functions in your PHP code to configure it.
opcache_reset(); // 重置opcache缓存
opcache_invalidate($file, $force = false); // 强制重新编译特定文件
opcache_compile_file($file); // 编译特定文件
opcache_get_configuration(); // 获取opcache配置信息
opcache_get_status(); // 获取opcache状态信息

The opcache can be dynamically configured and managed through these functions.

bannerAds