The behaviour of these functions is affected by settings in php.ini.
Where a configuration setting may be set.Here's a short explanation of the configuration directives.
opcache.enable boolopcache.enable can not be enabled at runtime through ini_set(), it can only be disabled. Trying to enable it in a script will generate a warning.opcache.enable_cli boolopcache.memory_consumption int"8", which is enforced if a smaller value is set.opcache.interned_strings_buffer intNote: Prior to PHP 8.4.0, the maximum value was 4095 megabytes on all architectures.
opcache.max_accelerated_files int{ 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_percentage int"50", which is enforced if a larger value is set.opcache.use_cwd boolopcache.validate_timestamps boolIf 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.
Note: OPcache 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_freq int0 will result in OPcache checking for updates on every request. This configuration directive is ignored if opcache.validate_timestamps is disabled.opcache.revalidate_path boolopcache.save_comments boolopcache.fast_shutdown boolopcache.enable_file_override boolopcache.optimization_level int0x7FFEBFFF, 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 |
Note: Safe vs Unsafe Optimizations
Safe 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
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_hack boolopcache.dups_fix boolopcache.blacklist_filename string; 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.php
opcache.max_file_size int0, all files will be cached.opcache.consistency_checks intNote: Disabled as of 8.1.18 and 8.2.5. Removed as of PHP 8.3.0.
opcache.force_restart_timeout intopcache.error_log stringstderr, and will result in logs being sent to standard error (which will be the Web server error log in most cases).opcache.log_verbosity_level intopcache.record_warnings boolopcache.preferred_memory_model stringmmap, shm, posix and win32.opcache.protect_memory boolopcache.mmap_base stringopcache.restrict_api string"" means no restriction.opcache.file_update_protection string0. This will allow files to be cached immediately.opcache.huge_code_pages boolopcache.lockfile_path stringopcache.opt_debug_level stringopcache.file_cache string"" disables file based caching.opcache.file_cache_only boolNote: Prior 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_checks boolopcache.file_cache_fallback boolopcache.file_cache_only=1 for a certain process that failed to reattach to shared memory (Windows only). Explicitly enabling the file cache is required.Disabling this configuration option may prevent processes to start, and is therefore discouraged.
opcache.validate_permission boolopcache.validate_root boolopcache.preload stringNote: Preloading is not supported on Windows.
opcache.preload_user stringroot. 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 CLI SAPI or phpdbg SAPI.opcache.cache_id stringOn 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.
For IIS, different application pools can have their own OPcache instance by using the environment variable APP_POOL_ID as opcache.cache_id.
opcache.jit string|intdisable: Completely disabled, cannot be enabled at runtime.off: Disabled, but can be enabled at runtime.tracing/on: Use tracing JIT. Enabled by default and recommended for most users.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."tracing" mode corresponds to CRTO = 1254, the "function" mode corresponds to CRTO = 1205.opcache.jit_buffer_size intopcache.jit_debug intZEND_JIT_DEBUG).opcache.jit_bisect_limit intopcache.jit=1215. See more in opcache.jit option.opcache.jit_prof_threshold floatopcache.jit_max_root_traces intopcache.jit_max_side_traces intopcache.jit_max_exit_counters intopcache.jit_hot_loop int[0,255]; for any setting out of this range, e.g. -1 or 256, default value will be used instead. 0 will disable JIT to trace and compile any loops.opcache.jit_hot_func int[0,255]; for any setting out of this range, e.g. -1 or 256, default value will be used instead. 0 will disable JIT to trace and compile any functions.opcache.jit_hot_return int[0,255]; for any setting out of this range, e.g. -1 or 256, default value will be used instead. 0 will disable JIT to trace and compile any returns.opcache.jit_hot_side_exit int[0,255]; for any setting out of this range, e.g. -1 or 256, default value will be used instead. 0 will disable JIT to trace and compile any side exits.opcache.jit_blacklist_root_trace intopcache.jit_blacklist_side_trace intopcache.jit_max_loop_unrolls intopcache.jit_max_recursive_calls intopcache.jit_max_recursive_returns intopcache.jit_max_polymorphic_calls int