OPcache configuration options
OPcache configuration optionsNameDefaultChangeableChangelogopcache.enable1INI_ALLopcache.enable_cli0INI_SYSTEMBetween PHP 7.1.2 and 7.1.6 inclusive, the default was 1opcache.memory_consumption128INI_SYSTEMopcache.interned_strings_buffer8INI_SYSTEMopcache.max_accelerated_files10000INI_SYSTEMopcache.max_wasted_percentage5INI_SYSTEMopcache.use_cwd1INI_SYSTEMopcache.validate_timestamps1INI_ALLopcache.revalidate_freq2INI_ALLopcache.revalidate_path0INI_ALLopcache.save_comments1INI_SYSTEMopcache.fast_shutdown0INI_SYSTEMRemoved in PHP 7.2.0opcache.enable_file_override0INI_SYSTEMopcache.optimization_level0x7FFEBFFFINI_SYSTEMChanged from 0x7FFFBFFF in PHP 7.3.0opcache.inherited_hack1INI_SYSTEMRemoved in PHP 7.3.0opcache.dups_fix0INI_ALLopcache.blacklist_filename""INI_SYSTEMopcache.max_file_size0INI_SYSTEMopcache.consistency_checks0INI_ALLDisabled as of 8.1.18 and 8.2.5. Removed as of PHP 8.3.0.opcache.force_restart_timeout180INI_SYSTEMopcache.error_log""INI_SYSTEMopcache.log_verbosity_level1INI_SYSTEMopcache.record_warnings0INI_SYSTEMAvailable as of PHP 8.0.0opcache.preferred_memory_model""INI_SYSTEMopcache.protect_memory0INI_SYSTEMopcache.mmap_basenullINI_SYSTEMWindows only.opcache.restrict_api""INI_SYSTEMopcache.file_update_protection2INI_ALLopcache.huge_code_pages0INI_SYSTEMopcache.lockfile_path"/tmp"INI_SYSTEMopcache.opt_debug_level0INI_SYSTEMAvailable as of PHP 7.1.0opcache.file_cachenullINI_SYSTEMopcache.file_cache_only0INI_SYSTEMopcache.file_cache_consistency_checks1INI_SYSTEMopcache.file_cache_fallback1INI_SYSTEMWindows only.opcache.validate_permission0INI_SYSTEMAvailable as of PHP 7.0.14opcache.validate_root0INI_SYSTEMAvailable as of PHP 7.0.14opcache.preload""INI_SYSTEMAvailable as of PHP 7.4.0opcache.preload_user""INI_SYSTEMAvailable as of PHP 7.4.0opcache.cache_id""INI_SYSTEMWindows only. Available as of PHP 7.4.0opcache.jit"disable"INI_ALLAvailable as of PHP 8.0.0. Prior to PHP 8.4.0, the default value was "tracing".opcache.jit_buffer_size64MINI_SYSTEMAvailable as of PHP 8.0.0. Prior to PHP 8.4.0, the default value was 0.opcache.jit_debug0INI_ALLAvailable as of PHP 8.0.0opcache.jit_bisect_limit0INI_ALLAvailable as of PHP 8.0.0opcache.jit_prof_threshold0.005INI_ALLAvailable as of PHP 8.0.0opcache.jit_max_root_traces1024INI_SYSTEMAvailable as of PHP 8.0.0opcache.jit_max_side_traces128INI_SYSTEMAvailable as of PHP 8.0.0opcache.jit_max_exit_counters8192INI_SYSTEMAvailable as of PHP 8.0.0opcache.jit_hot_loop61INI_SYSTEMAvailable as of PHP 8.0.0. Before PHP 8.5.0, the default value was 64opcache.jit_hot_func127INI_SYSTEMAvailable as of PHP 8.0.0opcache.jit_hot_return8INI_SYSTEMAvailable as of PHP 8.0.0opcache.jit_hot_side_exit8INI_SYSTEMAvailable as of PHP 8.0.0opcache.jit_blacklist_root_trace16INI_ALLAvailable as of PHP 8.0.0opcache.jit_blacklist_side_trace8INI_ALLAvailable as of PHP 8.0.0opcache.jit_max_loop_unrolls8INI_ALLAvailable as of PHP 8.0.0opcache.jit_max_recursive_calls2INI_ALLAvailable as of PHP 8.0.0opcache.jit_max_recursive_returns2INI_ALLAvailable as of PHP 8.0.0opcache.jit_max_polymorphic_calls2INI_ALLAvailable as of PHP 8.0.0 Constants
Runtime Runtime
| Name | Default | Changeable | Changelog |
|---|---|---|---|
| opcache.enable | 1 | INI_ALL | |
| opcache.enable_cli | 0 | INI_SYSTEM | Between PHP 7.1.2 and 7.1.6 inclusive, the default was 1 |
| opcache.memory_consumption | 128 | INI_SYSTEM | |
| opcache.interned_strings_buffer | 8 | INI_SYSTEM | |
| opcache.max_accelerated_files | 10000 | INI_SYSTEM | |
| opcache.max_wasted_percentage | 5 | INI_SYSTEM | |
| opcache.use_cwd | 1 | INI_SYSTEM | |
| opcache.validate_timestamps | 1 | INI_ALL | |
| opcache.revalidate_freq | 2 | INI_ALL | |
| opcache.revalidate_path | 0 | INI_ALL | |
| opcache.save_comments | 1 | INI_SYSTEM | |
| opcache.fast_shutdown | 0 | INI_SYSTEM | Removed in PHP 7.2.0 |
| opcache.enable_file_override | 0 | INI_SYSTEM | |
| opcache.optimization_level | 0x7FFEBFFF | INI_SYSTEM | Changed from 0x7FFFBFFF in PHP 7.3.0 |
| opcache.inherited_hack | 1 | INI_SYSTEM | Removed in PHP 7.3.0 |
| opcache.dups_fix | 0 | INI_ALL | |
| opcache.blacklist_filename | "" | INI_SYSTEM | |
| opcache.max_file_size | 0 | INI_SYSTEM | |
| opcache.consistency_checks | 0 | INI_ALL | Disabled as of 8.1.18 and 8.2.5. Removed as of PHP 8.3.0. |
| opcache.force_restart_timeout | 180 | INI_SYSTEM | |
| opcache.error_log | "" | INI_SYSTEM | |
| opcache.log_verbosity_level | 1 | INI_SYSTEM | |
| opcache.record_warnings | 0 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.preferred_memory_model | "" | INI_SYSTEM | |
| opcache.protect_memory | 0 | INI_SYSTEM | |
| opcache.mmap_base | null | INI_SYSTEM | Windows only. |
| opcache.restrict_api | "" | INI_SYSTEM | |
| opcache.file_update_protection | 2 | INI_ALL | |
| opcache.huge_code_pages | 0 | INI_SYSTEM | |
| opcache.lockfile_path | "/tmp" | INI_SYSTEM | |
| opcache.opt_debug_level | 0 | INI_SYSTEM | Available as of PHP 7.1.0 |
| opcache.file_cache | null | INI_SYSTEM | |
| opcache.file_cache_only | 0 | INI_SYSTEM | |
| opcache.file_cache_consistency_checks | 1 | INI_SYSTEM | |
| opcache.file_cache_fallback | 1 | INI_SYSTEM | Windows only. |
| opcache.validate_permission | 0 | INI_SYSTEM | Available as of PHP 7.0.14 |
| opcache.validate_root | 0 | INI_SYSTEM | Available as of PHP 7.0.14 |
| opcache.preload | "" | INI_SYSTEM | Available as of PHP 7.4.0 |
| opcache.preload_user | "" | INI_SYSTEM | Available as of PHP 7.4.0 |
| opcache.cache_id | "" | INI_SYSTEM | Windows only. Available as of PHP 7.4.0 |
| opcache.jit | "disable" | INI_ALL | Available as of PHP 8.0.0. Prior to PHP 8.4.0, the default value was "tracing". |
| opcache.jit_buffer_size | 64M | INI_SYSTEM | Available as of PHP 8.0.0. Prior to PHP 8.4.0, the default value was 0. |
| opcache.jit_debug | 0 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_bisect_limit | 0 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_prof_threshold | 0.005 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_max_root_traces | 1024 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.jit_max_side_traces | 128 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.jit_max_exit_counters | 8192 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.jit_hot_loop | 61 | INI_SYSTEM | Available as of PHP 8.0.0. Before PHP 8.5.0, the default value was 64 |
| opcache.jit_hot_func | 127 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.jit_hot_return | 8 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.jit_hot_side_exit | 8 | INI_SYSTEM | Available as of PHP 8.0.0 |
| opcache.jit_blacklist_root_trace | 16 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_blacklist_side_trace | 8 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_max_loop_unrolls | 8 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_max_recursive_calls | 2 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_max_recursive_returns | 2 | INI_ALL | Available as of PHP 8.0.0 |
| opcache.jit_max_polymorphic_calls | 2 | INI_ALL | Available as of PHP 8.0.0 |
Constants
Title
opcache.enableboolEnables the opcode cache. When disabled, code is not optimised or cached. The setting
opcache.enablecan not be enabled at runtime throughini_set(), it can only be disabled. Trying to enable it in a script will generate a warning.opcache.enable_cliboolEnables the opcode cache for the CLI version of PHP.
opcache.memory_consumptionintThe size of the shared memory storage used by OPcache, in megabytes. The minimum permissible value is
"8", which is enforced if a smaller value is set.When the JIT is enabled, the shared memory segment also holds the JIT buffer, so its total size is this value plus opcache.jit_buffer_size. OPcache first attempts to allocate the segment using HUGE PAGES, and silently falls back to regular pages when the operating system has not set aside enough of them.
opcache.interned_strings_bufferintThe amount of memory used to store interned strings, in megabytes. The maximum value is 32767 on 64bit architectures, and 4095 on 32bit architectures.
NotePrior to PHP 8.4.0, the maximum value was 4095 megabytes on all architectures.
opcache.max_accelerated_filesintThe maximum number of keys (and therefore scripts) in the OPcache hash table. The actual value used will be the first number in the set of prime numbers
{ 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793 }that is greater than or equal to the configured value. The minimum value is 200. The maximum value is 1000000. Values outside of this range are clamped to the permissible range.opcache.max_wasted_percentageintThe maximum percentage of wasted memory that is allowed before a restart is scheduled, if there is insufficient free memory. The maximum permissible value is
"50", which is enforced if a larger value is set.opcache.use_cwdboolIf enabled, OPcache appends the current working directory to the script key, thereby eliminating possible collisions between files with the same base name. Disabling this directive improves performance, but may break existing applications.
opcache.validate_timestampsboolIf enabled, OPcache will check for updated scripts every opcache.revalidate_freq seconds. When this directive is disabled, you must reset OPcache manually via
opcache_reset(),opcache_invalidate()or by restarting the Web server for changes to the filesystem to take effect.NoteOPcache may still validate the timestamp of a file at compile-time if opcache.file_update_protection or opcache.max_file_size options are set to non-zero values.
opcache.revalidate_freqintHow often to check script timestamps for updates, in seconds.
0will result in OPcache checking for updates on every request.This configuration directive is ignored if opcache.validate_timestamps is disabled.
opcache.revalidate_pathboolIf disabled, existing cached files using the same include_path will be reused. Thus, if a file with the same name is elsewhere in the include_path, it won't be found.
opcache.save_commentsboolIf disabled, all documentation comments will be discarded from the opcode cache to reduce the size of the optimised code. Disabling this configuration directive may break applications and frameworks that rely on comment parsing for annotations, including Doctrine, Zend Framework 2 and PHPUnit.
opcache.fast_shutdownboolIf enabled, a fast shutdown sequence is used that doesn't free each allocated block, but relies on the Zend Engine memory manager to deallocate the entire set of request variables en masse.
This directive has been removed in PHP 7.2.0. A variant of the fast shutdown sequence has been integrated into PHP and will be automatically used if possible.
opcache.enable_file_overrideboolWhen enabled, the opcode cache will be checked for whether a file has already been cached when
file_exists(),is_file()andis_readable()are called. This may increase performance in applications that check the existence and readability of PHP scripts, but risks returning stale data if opcache.validate_timestamps is disabled.opcache.optimization_levelintA bitmask that controls which optimisation passes are executed. The default value is
0x7FFEBFFF, which enables all safe optimizations. Disabling optimizations or enabling unsafe optimizations is mostly useful for debugging/developing the optimizer.Each bit in the bitmask enables a specific optimization pass:
Bit Pass Name Description Default 0 PASS_1 Simple peephole optimizations On 1 PASS_2 Unused (got merged into PASS_1) On 2 PASS_3 Simple jump optimization On 3 PASS_4 Call optimization On 4 PASS_5 Control Flow Graph based optimization On 5 PASS_6 Data Flow Analysis based optimization On 6 PASS_7 Whether call graph should be used for SSA-based optimizations On 7 PASS_8 Sparse conditional constant propagation On 8 PASS_9 Temporary variable optimization On 9 PASS_10 Removal of NOP opcodes On 10 PASS_11 Literal compaction On 11 PASS_12 Pre-compute call stack size On 12 PASS_13 Unused variable removal On 13 PASS_14 Dead code elimination On 14 PASS_15 Collect and substitute constant declarations (unsafe) Off 15 PASS_16 Trivial function inlining (part of call optimization) On 16 (Flag) Ignore possibility of operator overloading (unsafe) Off NoteSafe optimizations (enabled by default) preserve the exact behavior of PHP code while improving performance. They include dead code elimination, constant folding, and jump optimization.
Unsafe optimizations (disabled by default) may alter behavior in edge cases:
Bit 14: Collecting constants. Constants are substituted at compile-time, ignoring runtime declaration order:
php<?php echo getA(); // Outputs: "hello" instead of throwing an Error const A = "hello"; function getA() { return A; }- Bit 16: Ignoring operator overloading. Unsafe when using classes with
do_operation(e.g. GMP, BCMath) in arithmetic operations. With type declarations, the optimizer can apply the same optimizations safely.
opcache.inherited_hackboolThis configuration directive is ignored.
opcache.dups_fixboolThis hack should only be enabled to work around "Cannot redeclare class" errors.
opcache.blacklist_filenamestringThe location of the OPcache blacklist file. A blacklist file is a text file containing the names of files that should not be accelerated, one per line. Wildcards are allowed, and prefixes can also be provided. Lines starting with a semi-colon are ignored as comments.
A simple blacklist file might look as follows:
php; Matches a specific file. /var/www/broken.php ; A prefix that matches all files starting with x. /var/www/x ; A wildcard match. /var/www/*-broken.phpopcache.max_file_sizeintThe maximum file size that will be cached, in bytes. If this is
0, all files will be cached.opcache.consistency_checksintIf non-zero, OPcache will verify the cache checksum every N requests, where N is the value of this configuration directive. This should only be enabled when debugging, as it will impair performance.
NoteDisabled as of 8.1.18 and 8.2.5. Removed as of PHP 8.3.0.
opcache.force_restart_timeoutintThe length of time to wait for a scheduled restart to begin if the cache isn't active, in seconds. If the timeout is hit, then OPcache assumes that something is wrong and will kill the processes holding locks on the cache to permit a restart.
If opcache.log_verbosity_level is set to 2 or above, a warning will be recorded in the error log when this occurs.
This directive is not supported on Windows.
opcache.error_logstringThe error log for OPcache errors. An empty string is treated the same as
stderr, and will result in logs being sent to standard error (which will be the Web server error log in most cases).opcache.log_verbosity_levelintThe log verbosity level. By default, only fatal errors (level 0) and errors (level 1) are logged. Other levels available are warnings (level 2), information messages (level 3) and debug messages (level 4).
opcache.record_warningsboolIf enabled, OPcache will record compile-time warnings and replay them on the next include, even if it is served from cache.
opcache.preferred_memory_modelstringThe preferred memory model for OPcache to use. If left empty, OPcache will choose the most appropriate model, which is the correct behaviour in virtually all cases.
Possible values include
mmap,shm,posixandwin32.opcache.protect_memoryboolProtects shared memory from unexpected writes while executing scripts. This is useful for internal debugging only.
opcache.mmap_basestringThe base used for shared memory segments on Windows. All PHP processes have to map shared memory into the same address space. Using this directive allows "Unable to reattach to base address" errors to be fixed.
opcache.restrict_apistringAllows calling OPcache API functions only from PHP scripts which path is started from specified string. The default
""means no restriction.opcache.file_update_protectionstringPrevents caching files that are less than this number of seconds old. It protects from caching of incompletely updated files. In case all file updates are atomic, performance can be increased by setting this to
0. This will allow files to be cached immediately.opcache.huge_code_pagesboolEnables or disables copying of PHP code (text segment) into HUGE PAGES. This should improve performance, but requires appropriate OS configuration. Only the text segment of the PHP binary is remapped; the shared memory segment described under opcache.memory_consumption is unaffected by this directive. When the remapping fails, OPcache emits an
E_WARNING. Available on Linux as of PHP 7.0.0, and on FreeBSD as of PHP 7.4.0.opcache.lockfile_pathstringAbsolute path used to store shared lockfiles (for *nix only)
opcache.opt_debug_levelstringProduces opcode dumps for debugging different stages of optimizations. 0x10000 will output opcodes as the compiler produced them before any optimization occurs while 0x20000 will output optimized codes.
opcache.file_cachestringEnables 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_onlyboolEnables or disables opcode caching in shared memory.
NotePrior to PHP 8.1.0, disabling this directive with an already populated file cache required to manually clear the file cache.
opcache.file_cache_consistency_checksboolEnables or disables checksum validation when script loaded from file cache.
opcache.file_cache_fallbackboolImplies
opcache.file_cache_only=1for a certain process that failed to reattach to shared memory (Windows only). Explicitly enabling the file cache is required.CautionDisabling this configuration option may prevent processes to start, and is therefore discouraged.
opcache.validate_permissionboolValidates the cached file permissions against the current user.
opcache.validate_rootboolPrevents name collisions in chroot'ed environments. This should be enabled in all chroot'ed environments to prevent access to files outside the chroot.
opcache.preloadstringSpecifies a PHP script that is going to be compiled and executed at server start-up, and which may preload other files, either by
include()ing them or by using theopcache_compile_file()function. All the entities (e.g. functions and classes) defined in these files will be available to requests out of the box, until the server is shut down.NotePreloading is not supported on Windows.
opcache.preload_userstringLets the preloading to be run as the specified system user. This is useful for servers that startup as root before switching to an unprivileged system user. Preloading as root is not allowed by default for security reasons, unless this directive is explicitly set to
root. As of PHP 8.3.0, this directive does not need to be set in order to allow preloading while running as root when using the Sapi or phpdbg SAPI.opcache.cache_idstringOn Windows, all processes running the same PHP SAPI under the same user account having the same cache ID share a single OPcache instance. The value of the cache ID can be freely chosen.
TipFor IIS, different application pools can have their own OPcache instance by using the environment variable
APP_POOL_IDasopcache.cache_id.opcache.jitstring|intFor typical usage, this option accepts one of four string values:
disable: Completely disabled, cannot be enabled at runtime.off: Disabled, but can be enabled at runtime.tracing/on: Use tracing JIT. Recommended for most users. Prior to PHP 8.4.0, this was the default value; as of PHP 8.4.0 the default isdisable.function: Use function JIT.
For advanced usage, this option accepts a 4-digit integer
CRTO, where the digits mean:C(CPU-specific optimization flags)0: Disable CPU-specific optimization.1: Enable use of AVX, if the CPU supports it.
R(register allocation)0: Don't perform register allocation.1: Perform block-local register allocation.2: Perform global register allocation.
T(trigger)0: Compile all functions on script load.1: Compile functions on first execution.2: Profile functions on first request and compile the hottest functions afterwards.3: Profile on the fly and compile hot functions.4: Currently unused.5: Use tracing JIT. Profile on the fly and compile traces for hot code segments.
O(optimization level)0: No JIT.1: Minimal JIT (call standard VM handlers).2: Inline VM handlers.3: Use type inference.4: Use call graph.5: Optimize whole script.
The
"tracing"mode corresponds toCRTO = 1254, the"function"mode corresponds toCRTO = 1205.NoteAs of PHP 8.4.0, if JIT is enabled, PHP exits with a fatal error during startup when JIT initialization fails.
opcache.jit_buffer_sizeintThe amount of shared memory to reserve for compiled JIT code. A zero value disables the JIT.
Shorthandbytes
opcache.jit_debugintA bit mask specifying which JIT debug output to enable. For possible values, please consult zend_jit.h (search for macro definitions beginning with
ZEND_JIT_DEBUG).opcache.jit_bisect_limitintDebugging option that disables JIT compilation after compiling a certain number of functions. This may be helpful to bisect the source of a JIT miscompilation. Note: this option only works when JIT trigger is set to 0 (compile on script load) or 1 (compile on first execution), e.g.
opcache.jit=1215. See more in opcache.jit option.opcache.jit_prof_thresholdfloatWhen using the "profile on first request" trigger mode, this threshold determines whether a function is considered hot. The number of calls to the function divided by the number of calls to all functions must be above the threshold. For example, a threshold of 0.005 means that functions that made up more than 0.5% of all calls will be JIT compiled.
opcache.jit_max_root_tracesintMaximum number of root traces. The root trace is an execution flow taking one path through the code firstly, which is a unit of JIT compilation. JIT will not compile new code if it reaches this limit.
opcache.jit_max_side_tracesintMaximum number of side traces a root trace may have. The side trace is another execution flow that does not follow the path of compiled root trace. Side traces belonging to the same root trace will not be compiled if it reaches this limit.
opcache.jit_max_exit_countersintMaximum number of side trace exit counters. This limits the total number of side traces there may be, across all root traces.
opcache.jit_hot_loopintAfter how many iterations a loop is considered hot. Valid value range is
[0,255]; for any setting out of this range, e.g.-1or256, default value will be used instead.0will disable JIT to trace and compile any loops.NoteIt is recommended that this parameter is set to a prime number, to prevent it from being a multiple of loop iteration counts.
opcache.jit_hot_funcintAfter how many calls a function is considered hot. Valid value range is
[0,255]; for any setting out of this range, e.g.-1or256, default value will be used instead.0will disable JIT to trace and compile any functions.opcache.jit_hot_returnintAfter how many returns a return is considered hot. Valid value range is
[0,255]; for any setting out of this range, e.g.-1or256, default value will be used instead.0will disable JIT to trace and compile any returns.opcache.jit_hot_side_exitintAfter how many exits a side exit is considered hot. Valid value range is
[0,255]; for any setting out of this range, e.g.-1or256, default value will be used instead.0will disable JIT to trace and compile any side exits.opcache.jit_blacklist_root_traceintMaximum number of times the compilation of a root trace is attempted before it is blacklisted.
opcache.jit_blacklist_side_traceintMaximum number of times the compilation of a side trace is attempted before it is blacklisted.
opcache.jit_max_loop_unrollsintMaximum number of attempts to unroll a loop in a side trace, trying to reach the root trace and close the outer loop.
opcache.jit_max_recursive_callsintMaximum number of unrolled recursive call loops.
opcache.jit_max_recursive_returnsintMaximum number of unrolled recursive return loops.
opcache.jit_max_polymorphic_callsintMaximum number of attempts to inline polymorphic (dynamic or method) calls. Calls above this limit are treated as megamorphic and are not inlined.