Home  >  Article  >  Backend Development  >  How to install and configure ZendOpcache

How to install and configure ZendOpcache

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-07-23 09:17:311836browse

Zend, the company behind the PHP development team, recently open sourced its PHP acceleration product Zend Optimizer. The new project is hosted on Github and the project name is ZendOptimizerPlus. Today we will talk about ZendOpcache.

How to install and configure ZendOpcache

Introduction

Zend Optimizer speeds up PHP execution by caching and optimizing opcode. It stores presets in shared memory. Compile PHP scripts to improve PHP performance. This operation eliminates the process of reading PHP files from disk and then compiling them. In addition, it also provides a small amount of bytecode optimization mode to make the code execute faster.

Applicability

The current version of Zend Optimizer is suitable for PHP 5.2.*, 5.3.*, 5.4.* and the PHP-5.5 development branch. Support for PHP 5.2 may be canceled in the future Support.

Installation

First download the source code of Zend Optimizer:

http://pecl.php.net/package/ZendOpcache

Currently, I am using the beta version of 7.0.1, download After decompression, compile:

wget http://pecl.php.net/get/zendopcache-7.0.1.tgz
tar xzf zendopcache-7.0.1.tgz
cd zendopcache-7.0.1
phpize
./configure --with-php-config=/path_to_php_bin/php-config
make
make install

ConfigurationEdit php.ini

zend_extension=/...full_path.../opcache.so
#以下是开发组推荐配置
opcache.memory_consumption=128     
opcache.interned_strings_buffer=8     
opcache.max_accelerated_files=4000     
opcache.revalidate_freq=60     
opcache.fast_shutdown=1     
opcache.enable_cli=1

Restart your php cgi or Apache.

Detailed explanation of configuration parameters

  • opcache.enable(Default value: 1)

    Zend Optimizer switch, when turned off, the code will no longer be optimized.

  • opcache.memory_consumption(Default: 64)

    Zend Optimizer The size of shared memory, how much precompiled PHP code can be stored in total (unit: MB).

  • opcache.interned_strings_buffer(Default value: 4)

    The total memory occupied by interned strings in Zend Optimizer. (Unit :MB)

  • opcache.max_accelerated_files(Default: 2000)

    Zend Optimizer Maximum number of keys in the hash table (a script The file should correspond to a key, so it should be the maximum number of files allowed to be cached). This value is actually the first in the prime number list {223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987} A number greater than the set value. Value setting range: 200 – 100000

  • ##opcache.max_wasted_percentage(default value: 5)

    " "Waste" memory reaches the percentage corresponding to this value, a restart schedule will be initiated.

  • opcache.use_cwd(Default value: 1)

    Enable this command, Zend Optimizer will automatically append the name of the current working directory to the script key, thereby eliminating key-value naming conflicts between files with the same name. Turning this command off will improve performance, but will cause problems for existing applications Break.

  • opcache.validate_timestamps(Default: 1)

    When disabled, you must manually reset Zend Optimizer or restart the web server , to make file system changes take effect. The frequency of checks is controlled by the directive "opcache.revalidate_freq".

  • ##opcache.revalidate_freq

    (Default: 2)How often (in seconds) to check the file timestamp to change the allocation of shared memory. "1" means checking once a second, but once per request. "0" means always checking.

  • opcache.revalidate_path

    (Default: 0)Enable or disable optimization of file search in include_path. If file search is disabled And this cached file can be found in the same include_path, and the file search will not continue. Therefore, if there is a file with the same name elsewhere in the include_path, it will not be found. If this optimization has an impact on your application , then it should be allowed to search. By default, the directive is disabled, which means that optimization is active.

  • opcache.save_comments

    ( Default value: 1) If disabled, all documentation comments are stripped from the code to reduce the size of the optimized code. Disabling "documentation comments" may break some existing applications and frameworks (e.g. : Doctrine, ZF2, PHPUnit).

  • opcache.load_comments

    (Default: 1)If disabled, PHP documentation comments will not Read from SHM (shared memory). Although "documentation comments" will still be stored (save_comments=1), those comments that are not used anyway do not need to be read by the application.

  • opcache.fast_shutdown

    (Default: 0)If enabled, a fast shutdown queue is used to speed up the code. The fast shutdown queue does not release each allocated block , instead let the Zend engine memory manager do the job.

  • opcache.enable_file_override

    (Default: 0)Allow overwriting of files Optimization features for existence (file_exists, etc.).

  • opcache.optimization_level

    (Default: 0xffffffff)A bitmask where each bit allows or disables the corresponding cache pass.

  • opcache.inherited_hack

    (Default: 1)

    Enabling this Hack can temporarily solve the "can't redeclare class" error. Zend Optimizer stores where DECLARE_CLASS opcodes use inheritance (these are the only opcodes that can be executed by PHP, but they may also be caused by optimization The parent class cannot be found and cannot be executed). When the file is read, the Optimizer will try to bind the inherited class through the current environment. The problem with this is that the DECLARE_CLASS opcode may not be needed by the current script, if The script requires the opcode to at least complete the class definition operation, then it will not be executed. This command is disabled by default, which means that the optimization is effective. This is no longer required in PHP 5.3 and above, and this The setting will not take effect.

  • opcache.dups_fix(Default: 0)

    Enabling this Hack can temporarily solve "can' t redeclare class” error.

  • ##opcache.blacklist_filename(Default: None)

    The location of the Zend Optimizer blacklist file.

    The Zend Optimizer blacklist is a text file containing the names of files that cannot be accelerated. The file format is one file name per line. The file name must be a complete path or a file prefix (such as: /var/www/x All files or directories starting with 'x' in the /var/www file and directory are blocked). Files that need to be blocked usually meet one of the following three reasons:
    1) The directory contains automatically generated code, such as Smarty or ZFW cache.
    2) The code does not run well when executing acceleration, thus delaying compile-time evaluation.
    3) The code triggers a Zend Optimizer Bug

  • opcache.max_file_size(Default: 0)

    Screen the cache of large files by file size. By default all files will be cached.

  • opcache.consistency_checks(Default: 0)

    Check cache verification every N requests. The default value of 0 means that the check is disabled. Due to the calculation of the verification value Impairing performance, this command should be turned on during development and debugging.

  • opcache.force_restart_timeout(Default value: 180)

    From After the cache is not accessed, how long to wait (in seconds) before scheduling a restart. Zend Optimizer relies on this instruction to determine whether a process may have problems during processing. After this period of time (waiting time), it is assumed that Zend Optimizer occurs problems, and begins killing processes that still hold restart prevention locks. When this occurs, a "killed locker" error will be logged to the Apache logs if the log level is level 3 or above.

  • opcache.error_log(Default: None)

    The error log file name of Zend Optimizer. Leave blank to use standard error output (stderr).

  • opcache.log_verbosity_level(Default: 1)

    Direct error messages to the Web server log. The default is only fatal errors (level 0 ) or errors (level 1) will be logged. You can also allow warnings (level 2), prompt messages (level 3) or debug messages (level 4) to be logged.

  • opcache.preferred_memory_model(Default: None)

    The preferred background for memory sharing. Leave it blank to let the system choose.

  • opcache.protect_memory(Default: 0)

    Prevent shared memory from being accidentally written during script execution, for internal debugging only.

  • opcache.mmap_base(Default: None)

    Shared memory segment mapping base (Windows only). All PHP processes must map to the same shared memory address space. This directive is used Manually fix the "Unable to reattach to base address" error.

Recommended learning:

php video tutorial

The above is the detailed content of How to install and configure ZendOpcache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete