PHP Conference Nagoya 2025

Configurazione di Runtime

Il comportamento di queste funzioni è influenzato dalle impostazioni di php.ini.

OPcache configuration options
Nome Default Modificabile Storico dei cambiamenti
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 "tracing" INI_ALL Available as of PHP 8.0.0
opcache.jit_buffer_size 0 INI_SYSTEM Available as of PHP 8.0.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 64 INI_SYSTEM Available as of PHP 8.0.0
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
Per maggiori dettagli e definizioni sui modi INI_*, vedere Where a configuration setting may be set.

Breve descrizione dei parametri di configurazione.

opcache.enable bool

Enables the opcode cache. When disabled, code is not optimised or cached. The setting opcache.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 bool

Enables the opcode cache for the CLI version of PHP.

opcache.memory_consumption int

The 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.

opcache.interned_strings_buffer int

The amount of memory used to store interned strings, in megabytes.

opcache.max_accelerated_files int

The 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_percentage int

The 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_cwd bool

If 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_timestamps bool

If 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.

Nota: 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 int

How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.

This configuration directive is ignored if opcache.validate_timestamps is disabled.

opcache.revalidate_path bool

If 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_comments bool

If 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_shutdown bool

If 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_override bool

When enabled, the opcode cache will be checked for whether a file has already been cached when file_exists(), is_file() and is_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_level int

A bitmask that controls which optimisation passes are executed. The default is to apply all safe optimizations. Changing the default is mostly useful for debugging/developing the optimizer (see also opcache.opt_debug_level).

opcache.inherited_hack bool

This configuration directive is ignored.

opcache.dups_fix bool

This hack should only be enabled to work around "Cannot redeclare class" errors.

opcache.blacklist_filename string

The 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:

; 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 int

The maximum file size that will be cached, in bytes. If this is 0, all files will be cached.

opcache.consistency_checks int

If 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.

Nota:

Disabled as of 8.1.18 and 8.2.5. Removed as of PHP 8.3.0.

opcache.force_restart_timeout int

The 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_log string

The 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_level int

The 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_warnings bool

If enabled, OPcache will record compile-time warnings and replay them on the next include, even if it is served from cache.

opcache.preferred_memory_model string

The 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, posix and win32.

opcache.protect_memory bool

Protects shared memory from unexpected writes while executing scripts. This is useful for internal debugging only.

opcache.mmap_base string

The 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_api string

Allows calling OPcache API functions only from PHP scripts which path is started from specified string. The default "" means no restriction.

opcache.file_update_protection string

Prevents 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_pages bool

Enables or disables copying of PHP code (text segment) into HUGE PAGES. This should improve performance, but requires appropriate OS configuration. Available on Linux as of PHP 7.0.0, and on FreeBSD as of PHP 7.4.0.

opcache.lockfile_path string

Absolute path used to store shared lockfiles (for *nix only)

opcache.opt_debug_level string

Produces 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_cache string

Enables 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_only bool

Enables or disables opcode caching in shared memory.

Nota:

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 bool

Enables or disables checksum validation when script loaded from file cache.

opcache.file_cache_fallback bool

Implies opcache.file_cache_only=1 for a certain process that failed to reattach to shared memory (Windows only). Explicitly enabling the file cache is required.

Attenzione

Disabling this configuration option may prevent processes to start, and is therefore discouraged.

opcache.validate_permission bool

Validates the cached file permissions against the current user.

opcache.validate_root bool

Prevents name collisions in chroot'ed environments. This should be enabled in all chroot'ed environments to prevent access to files outside the chroot.

opcache.preload string

Specifies a PHP script that is going to be compiled and executed at server start-up, and which may preload other files, either by includeing them or by using the opcache_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.

Nota:

Preloading is not supported on Windows.

opcache.preload_user string

Lets 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.

opcache.cache_id string

On 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.

Suggerimento

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|int

For 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. 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.
The "tracing" mode corresponds to CRTO = 1254, the "function" mode corresponds to CRTO = 1205.

opcache.jit_buffer_size int

The amount of shared memory to reserve for compiled JIT code. A zero value disables the JIT.

Quando un integer è usato, il valore è misurato in byte. Si può anche usare una notazione abbreviata come descritto in questa FAQ.
opcache.jit_debug int

A 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_limit int

Debugging 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_threshold float

When 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_traces int

Maximum 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_traces int

Maximum 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_counters int

Maximum number of side trace exit counters. This limits the total number of side traces there may be, across all root traces.

opcache.jit_hot_loop int

After how many iterations a loop is considered hot. Valid value range is [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

After how many calls a function is considered hot. Valid value range is [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

After how many returns a return is considered hot. Valid value range is [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

After how many exits a side exit is considered hot. Valid value range is [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 int

Maximum number of times the compilation of a root trace is attempted before it is blacklisted.

opcache.jit_blacklist_side_trace int

Maximum number of times the compilation of a side trace is attempted before it is blacklisted.

opcache.jit_max_loop_unrolls int

Maximum 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_calls int

Maximum number of unrolled recursive call loops.

opcache.jit_max_recursive_returns int

Maximum number of unrolled recursive return loops.

opcache.jit_max_polymorphic_calls int

Maximum number of attempts to inline polymorphic (dynamic or method) calls. Calls above this limit are treated as megamorphic and are not inlined.

add a note

User Contributed Notes 7 notes

up
20
damien at overeem dot org
7 years ago
When using PHP on a windows platform and enabling opcache, you might run into occasional 500 errors. These will appear to show up entirely random.

When this happens, your windows Event log (Windows Logs/Application) will show (probably multiple) entries from Zend OPcache with Event ID 487. Further information will state the following error message: "Base address marks unusable memory region".

This issue can be resolved by adding the following to your php.ini:

opcache.mmap_base = 0x20000000

Unfortunately I do not know the significance of the value "0x20000000". I can only tell you that this value works to solve the problem (Tried and tested)
up
8
carneiro at isharelife dot com dot br
4 years ago
If you try to allocate more memory that is available using opcache.memory_consumption PHP stops working without any logs to help on debugging. This issue took me 4 hours to solve when creating a staging server with same configrations and less memory that was available on production server.
up
9
wessos at example dot org
5 years ago
The optimization levels as of php 7.3 are the following:

#define ZEND_OPTIMIZER_PASS_1 (1<<0) /* CSE, STRING construction */
#define ZEND_OPTIMIZER_PASS_2 (1<<1) /* Constant conversion and jumps */
#define ZEND_OPTIMIZER_PASS_3 (1<<2) /* ++, +=, series of jumps */
#define ZEND_OPTIMIZER_PASS_4 (1<<3) /* INIT_FCALL_BY_NAME -> DO_FCALL */
#define ZEND_OPTIMIZER_PASS_5 (1<<4) /* CFG based optimization */
#define ZEND_OPTIMIZER_PASS_6 (1<<5) /* DFA based optimization */
#define ZEND_OPTIMIZER_PASS_7 (1<<6) /* CALL GRAPH optimization */
#define ZEND_OPTIMIZER_PASS_8 (1<<7) /* SCCP (constant propagation) */
#define ZEND_OPTIMIZER_PASS_9 (1<<8) /* TMP VAR usage */
#define ZEND_OPTIMIZER_PASS_10 (1<<9) /* NOP removal */
#define ZEND_OPTIMIZER_PASS_11 (1<<10) /* Merge equal constants */
#define ZEND_OPTIMIZER_PASS_12 (1<<11) /* Adjust used stack */
#define ZEND_OPTIMIZER_PASS_13 (1<<12) /* Remove unused variables */
#define ZEND_OPTIMIZER_PASS_14 (1<<13) /* DCE (dead code elimination) */
#define ZEND_OPTIMIZER_PASS_15 (1<<14) /* (unsafe) Collect constants */
#define ZEND_OPTIMIZER_PASS_16 (1<<15) /* Inline functions */

Source: https://lxr.room11.org/xref/php-src%40master/ext/opcache/Optimizer/zend_optimizer.h
up
6
tizian dot schmidlin at gmail dot com
5 years ago
It should be noted that according to the original RFC (https://wiki.php.net/rfc/preload) `opcache.preload` caches preloaded files *forever* for all instances of the underlying PHP process.

That means, that hosting multiple websites on the same server might result in some unexpected behaviour.

Concrete example:
- you have a Symfony 3.2 App (which might be an endpoint of some type) and a Symfony 3.4 App (which might be your main application)
- both apps have a main Class called App that is in the same namespace (as it is usual, since the class name is unique to each project)
- depending on which app is loaded first, one or the other will work, since `opcache.preload` has no file based distinction of what class is used where and simply provides them to the user space

This is avoidable by simply not preloading user space classes or, if you work with FPM, by defining a pool for each app.

In order to optimize memory consumption, you might also use a common FPM Pool for all Symfony 3.4 Apps and preload the entire framework in there and simply not preload user space classes (which might be cached by opcache anyway but is slower, since it will be checked if the file has changed on every request).
up
4
bdurand at ensemblegroup dot net
7 years ago
It would appear as though the [opcache.enable] setting is indeed NOT PHP_INI_ALL.
For changing it within user.ini yields no effect when disabled at global level. user.ini is ignored for that setting.
up
1
JReezy
7 months ago
Despite the set of values for opcache.max_accelerated_files including the value 1048793, the maximum as stated is 1000000. If you select a number above 1000000 the value is set its default which is 10000.
up
0
daniel at elementor dot com
6 months ago
When opcache.use_cwd=0 include/require of relative paths from different directories will both resolve to the same (first) file.

Example dir structure:
app1
index.php
lib.php
app2
index.php
lib.php

both index.php(s):
include "lib.php";

app1/lib.php:
echo "app1";

app2/lib.php:
echo "app2";

both will echo "app1".
To Top