安装/配置
PHP 手册

运行时配置

这些函数的行为受 php.ini 中的设置影响。

OPcache configuration options
名字 默认 可修改范围 更新日志
opcache.enable "1" PHP_INI_ALL  
opcache.enable_cli "0" PHP_INI_SYSTEM  
opcache.memory_consumption "64" PHP_INI_SYSTEM  
opcache.interned_strings_buffer "4" PHP_INI_SYSTEM Available since PHP 5.3.0.
opcache.max_accelerated_files "2000" PHP_INI_SYSTEM  
opcache.max_wasted_percentage "5" PHP_INI_SYSTEM  
opcache.use_cwd "1" PHP_INI_SYSTEM  
opcache.validate_timestamps "1" PHP_INI_ALL  
opcache.revalidate_freq "2" PHP_INI_ALL  
opcache.revalidate_path "0" PHP_INI_ALL  
opcache.save_comments "1" PHP_INI_SYSTEM  
opcache.load_comments "1" PHP_INI_ALL  
opcache.fast_shutdown "0" PHP_INI_SYSTEM  
opcache.enable_file_override "0" PHP_INI_SYSTEM  
opcache.optimization_level "0xffffffff" PHP_INI_SYSTEM  
opcache.inherited_hack "1" PHP_INI_SYSTEM  
opcache.dups_fix "0" PHP_INI_ALL  
opcache.blacklist_filename "" PHP_INI_SYSTEM  
opcache.max_file_size "0" PHP_INI_SYSTEM  
opcache.consistency_checks "0" PHP_INI_ALL  
opcache.force_restart_timeout "180" PHP_INI_SYSTEM  
opcache.error_log "" PHP_INI_SYSTEM  
opcache.log_verbosity_level "1" PHP_INI_SYSTEM  
opcache.preferred_memory_model "" PHP_INI_SYSTEM  
opcache.protect_memory "0" PHP_INI_SYSTEM  
opcache.mmap_base NULL PHP_INI_SYSTEM  
有关 PHP_INI_* 样式的更多详情与定义,见 配置可被设定范围

这是配置指令的简短说明。

opcache.enable boolean

Enables the opcode cache. When disabled, code is not optimised and cached.

opcache.enable_cli boolean

Enables the opcode cache for the CLI version of PHP. This is mostly useful for testing and debugging.

opcache.memory_consumption integer

The size of the shared memory storage used by OPcache, in megabytes.

opcache.interned_strings_buffer integer

The amount of memory used to store interned strings, in megabytes. This configuration directive is ignored in PHP < 5.3.0.

opcache.max_accelerated_files integer

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 } that is bigger than the configured value. Only numbers between 200 and 100000 are allowed.

opcache.max_wasted_percentage integer

The maximum percentage of wasted memory that is allowed before a restart is scheduled.

opcache.use_cwd boolean

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 boolean

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.

opcache.revalidate_freq integer

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 if disabled.

opcache.revalidate_path boolean

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 boolean

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.load_comments boolean

If disabled, documentation comments won't be loaded from the opcode cache even if they exist. This can be used with opcache.save_comments to only load comments for applications that require them.

opcache.fast_shutdown boolean

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.

opcache.enable_file_override boolean

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 integer

A bitmask that controls which optimisation passes are executed.

opcache.inherited_hack boolean

In PHP < 5.3, OPcache stores the places where DECLARE_CLASS opcodes used inheritance; when the file is loaded, OPcache then tries to bind the inherited classes using the current environment. The problem is that while the DECLARE_CLASS opcode may not be needed for the current script, if the script requires that the opcode be defined, it may not run.

This configuration directive is ignored in PHP 5.3 and later.

opcache.dups_fix boolean

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 integer

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

opcache.consistency_checks integer

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.

opcache.force_restart_timeout integer

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 3 or above, an error will be recorded in the error log when this occurs.

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 integer

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

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.


安装/配置
PHP 手册