-
Notifications
You must be signed in to change notification settings - Fork 0
MLC OPcache installation and configuration
- Download the latest source from https://github.com/TerryE/opcache/archive/dev-filecache.zip
- phpize and configure for MLC OPcache mode
$PHP_DIR/bin/phpize ./configure \ --enable-opcache \ --enable-opcache-file-cache \ --enable-opcache-timing \ --with-php-config=$PHP_DIR/bin/php-config make
- Install opcache.so into PHP extension directory (you will need to sudo this).
make install
- Edit the php.ini to add
zend_extension=/...full path.../opcache.so
- You will also need to add at a minimum the opcache.cache_pattern and opcache.cache_file directives.
The following OPcache INI directives have a different meaning in MLC operation:
- opcache.memory_consumption (default "64"). This still refers to the OPcache shared memory storage size, but in this mode the memory is allocated in 8 Mb bricks on an as required basis.
The following OPcache INI directives have been added and apply to MLC operation:
- opcache.debug_flags (default "0"). A bitmask, where each bit enables or disables the debug logging class. Useful for internal debugging only, and only enabled on builds configured for debug. See OPcache diagnostic instrumentation for more details.
- opcache.cache_pattern (default "^"). An optional PCRE regexp matched against the requested script name.
- opcache.cache_file. Name of the file cache to be used with this request. Note that the name may contain the match placeholders $0..$9 which will be substituted with the corresponding match string from the cache_pattern. The file caching mode is only enabled if cache_file is non-blank and cache_pattern matches the requested script name.
-
opcache.compression_algo (default "1"). Set to one of the following list. Zlib generates
the smallest cache files, but is the slowest at cache priming and reloading. LZ4 gives the fastest
cache priming, but the largest caches. LZ4HC gives the best overall performance on reload
executions.
- Zlib deflate/inflate
- LZ4
- LZ4 High Compression
The following OPcache INI directives have the same meaning for both core and MLC OPcache.
- opcache.enable (default "1")
- opcache.enable_cli (default "0")
- opcache.interned_strings_buffer (default "4")
- opcache.max_accelerated_files (default "2000")
- opcache.use_cwd (default "1")
- opcache.validate_timestamps (default "1")
- opcache.revalidate_freq (default "2")
- opcache.revalidate_path (default "0")
- opcache.save_comments (default "1")
- opcache.load_comments (default "1")
- opcache.fast_shutdown (default "0")
- opcache.enable_file_override (default "0")
- opcache.optimization_level (default "0xffffffff")
- opcache.inherited_hack (default "1")
- opcache.dups_fix (default "0")
- opcache.blacklist_filename
- opcache.max_file_size (default "0")
- opcache.consistency_checks (default "0")
- opcache.error_log
- opcache.log_verbosity_level (default "1")
- opcache.max_wasted_percentage
- opcache.force_restart_timeout
- opcache.preferred_memory_model
- opcache.protect_memory
- opcache.mmap_base
The MC variant is enabled by configuring the OPcache build (as above) with the --enable-opcache-file-cache option. It only applies in CLI and CGI modes if the opcache.cache_pattern and opcache.cache_file are correctly configured to define a cache file.
- All code changes to the base OPcache files are implemented by #ifdef gated code blocks, or by macros which generate null strings on non-enabled configurations. This effectively results in the compiled OPcache being identical to the base Zend OPcache code-base if the file-cache option is not enabled.
- The executable code generated by the enabling the file-cache option includes the appropriate runtime checks on the ZSMMG(use_file_cache) which is only set in CLI and CGI modes on a suitable request scriptname match as discussed below. This again ensures that the execution paths are functionally identical to the base OPcache for other SAPI modes.
- Within the execution paths enabled by the ZSMMG(use_file_cache) flag, one of two states exists depending on ZFCSG(file_cache_dirty). This flag is set if any script fails the normal validity checks. Whilst it is clear, then full multi-level caching takes place. If it is set then OPcache is effectively disabled and reverts back to normal (non-cached) mode. Any cache file opened during the execution is deleted at script run-down. This logic indirectly implements a very simple integrity strategy for file caches: no modification or updates are attempted if any validation failure occurs; the cache is deleted and the script execution continues in uncached mode, leaving a subsequent request to rebuild a clean file cache.
MLC caching is enabled on a per request basis, depending on two opcache INI parameters:
- cache_pattern (default "^"). OPcache executes a PCRE regular expression match against the request scriptname using this pattern. The pattern may contain up to 9 match fields.
- cache_file. Name of the cache file to be used. The name may include the pattern substitution placeholders $0..$9, having the normal interpretation.
For file caching to be activated, the pattern must match the scriptname, and the (substituted) cache file string must be a valid filename. Note that both these parameters are INI_PERDIR, allowing them to be set in .user.ini configuration files for PHP versions 5.3 and greater. Here are some examples:
; Only cache index.php using a separate R/W directory opcache.cache_pattern="^/home/test/public_html/index\.php$" opcache.cache_file="/home/test/_cache/index.opcache"
; Cache all requests to /ucp using a separate common cache opcache.cache_pattern="^/home/test/public_html/ucp/.*\.php$" opcache.cache_file="/home/test/_cache/ucp.opcache"
; Cache all requests to the corresponding cache file in the cache directory hierarchy opcache.cache_pattern="^/home/test/public_html/(.*?)\.php[t5]?$" opcache.cache_file="/home/test/_cache/$1.opcache"