Opcache expansion under Linux

Source: Internet
Author: User
Tags phpinfo apache log zend

PHP 5.5.0 and subsequent versions have been bundled with the Opcache extension, only need to compile the installation, if you use the--disable-all parameter to disable the default extension of the build, you must use the--enable-opcache option to turn on Opcache.

After compiling, you can use the Zend_extension directive to load the Opcache extension into PHP. Use on non-Windows platforms zend_extension= path/opcache.so, the Windows platform uses Zend_extension=path/php_opcache.dll

Add or modify the following code in php.ini

 [zend opcache]zend_extension  =/usr/local/php/lib/php/extensions/ No-debug-non-zts-20090626 / Opcache.soopcache.memory_consumption  =64  opcache.interned_strings_buffer  =8  Span style= "color: #000000;" >opcache.max_accelerated_files  =4000   Opcache.force_restart_timeout  =180   Opcache.revalidate_freq  =60   Opcache.fast_shutdown  =1   OPCACHE.ENABLE_CLI  =1  


For an introduction to the above Opcache options, please refer to: http://www.php.net/manual/zh/opcache.configuration.php


Restart PHP, via Phpinfo (); Commands to view
Php.ini_opcache_extension


In the phpinfo () message, it is now important to see two messages:

Cache Hits (advanced cache hit)
Cache misses (advanced cache misses)

In these two messages, you can see how the cache is running, at a glance
What optimizations do caches bring? How much help is it to run your code?

Let's do a test to verify what Opcache is.

<? PHP Echo ' Opcache ';? >

This is a very simple PHP code, please save the demo.php file and then access, feel free to refresh, the Cache hits value will continue to increase, indicating that it worked,
Then you modify the code to:

<? PHP Echo ' Cache new ';? >


Refresh demo.php, should be able to see the effect, print out the value is still opcache, that is, the source is cached, it no longer resolves demo.php files, try to constantly refresh, detect how many seconds before updating.
Can be set: opcache.force_restart_timeout=180 time to control the update speed.

This is similar to the static file cache in the Web project, for example, we load a Web page, the browser will automatically help us to the JPG, CSS cache, except that PHP is not cached, each time you need an open file, parse the code,

The process of executing the code, and Opcache can solve this problem, the code will be cached to improve the speed of access.

Personal suggestion: The development environment does not need to open Opcache, the server is recommended to open, it will not be updated every day. The cache has its historical significance.

Note: Zend opcache conflicts with Eaccelerator. To install Zend Opcache, you may need to uninstall eaccelerator--first if you use this accelerator module.

The following information is reproduced in the
Detailed configuration parameters

Opcache.enable (default: 1)

Zend Optimizer + switch, code is no longer optimized when off.
Opcache.memory_consumption (default: 64)

Zend Optimizer + the size of shared memory, how many precompiled PHP code (in megabytes) can be stored in total.
Opcache.interned_strings_buffer (default: 4)

Zend Optimizer + interned the total amount of memory in the string. (Unit: MB)
Opcache.max_accelerated_files (default: 2000)

Zend Optimizer + maximum number of keys in a hash table (a script file should be one key, so it should be the maximum number of files allowed to cache). This value is actually a list of primes {223, 463, 983, 1979, 3907, 7963, 16229, 32 The first number in 531, 65407, 130987} that is greater than the set value. Value Setting Range: 200–100000
Opcache.max_wasted_percentage (default: 5)

"Wasted" memory reaches the percentage corresponding to this value, a restart schedule is initiated.
OPCACHE.USE_CWD (default: 1)

With this command on, Zend Optimizer + automatically appends the name of the current working directory to the script key to eliminate the key-value naming conflict between files of the same name. Closing this instruction will improve performance, but will cause damage to existing applications.
Opcache.validate_timestamps (default: 1)

When disabled, you must manually reset the Zend Optimizer + or restart the Web server for the file system changes to take effect. The frequency of the check is controlled by the instruction "Opcache.revalidate_freq".
Opcache.revalidate_freq (default: 2)

How long (in seconds) to check the file timestamp to change the allocation of shared memory. " 1″ represents one-second checksum, but it is one request at a time. "0″ means always checking.
Opcache.revalidate_path (default: 0)

Allows or disables the optimization of file searches in Include_path. If the file search is disabled and the cached file can be found in the same include_path, the file search will not go any further. Therefore, if there is a file of the same name elsewhere in the include_path, it will not be found. If this optimization has an impact on your application, then you should allow it to search. By default, directives are forbidden, which means that optimizations are in the active state.
Opcache.save_comments (default: 1)

If disabled, all document comments are removed from the code to reduce the size of the optimized code. Disabling the document comment may break some existing applications and frameworks (for example: Doctrine, ZF2, PHPUnit).
Opcache.load_comments (default: 1)

If disabled, PHP document annotations will not be read from SHM (shared memory). Although the document comment is still stored (save_comments=1), annotations that are not used in any way will not have to be read by the application.
Opcache.fast_shutdown (default: 0)

If turned on, a fast shutdown queue is used to speed up the code. The fast shutdown queue does not release each allocated block, but instead allows the Zend engine memory manager to do the job.
Opcache.enable_file_override (default: 0)

Allows for the optimization of file presence (file_exists, etc.) to be overwritten.
Opcache.optimization_level (default: 0xFFFFFFFF)

A bitmask in which each bit allows or disables the corresponding cache pass.
Opcache.inherited_hack (default: 1)

Enabling this hack can temporarily resolve the "can ' t Redeclare class" error. Zend Optimizer + stores Declare_class opcode using inheritance (these are the only opcode that can be executed by PHP, but it may not be possible to do so because the parent class that the optimization causes cannot be found). When the file is read, Optimizer Try to bind the inherited class through the current environment. The problem with this is. The Declare_class opcode may not be required by the current script, and it will not execute if the script requires the opcode to do at least the definition of the class. This command is disabled by default, which means that the optimization is valid. It is no longer required in PHP 5.3 and above, and this setting does not take effect.
Opcache.dups_fix (default: 0)

Enabling this hack can temporarily resolve the "can ' t Redeclare class" error.
Opcache.blacklist_filename (default: None)

Zend the location of the Optimizer + blacklist file.
Zend Optimizer + blacklist is a text file that contains filenames that cannot be accelerated. The file format is one filename per line. The filename must be a full path or a file prefix (such as:/var/www/x masks all the/var/www files and directories with ' X ' File or directory to begin with). Files that need to be masked usually meet one of the following three reasons:
1) The directory contains the automatically generated code, such as Smarty or ZFW cache.
2) The code does not run well when the acceleration is performed, which delays the compile-time evaluation.
3) The code triggers a Bug with Zend Optimizer +
Opcache.max_file_size (default: 0)

The cache of large files is removed by the file size screen. All files are cached by default.
Opcache.consistency_checks (default: 0)

The cache checksum is checked once per N requests. The default value of 0 indicates that the check is disabled. Because the checksum performance is calculated, this instruction should be opened tightly when developing debugging.
Opcache.force_restart_timeout (default: 180)

The time to wait (in seconds) to schedule a restart after the cache is not accessed. Zend Optimizer + relies on this directive to identify situations in which a process may have problems during processing. After this time (wait time), assume that Zend Optimizer + has some problems and starts to kill those processes that still hold the Prevent restart lock. When this happens, If the log level is 3 or higher, a "killed locker" error is logged to the Apache log.
Opcache.error_log (default: None)

Zend Optimizer + error log file name. Blank indicates that the standard error output (STDERR) is used.
Opcache.log_verbosity_level (default: 1)

Directs error messages to the WEB server log. The default is only fatal error (level 0) or error (Level 1) is 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. Leaving the system selected is left blank.
Opcache.protect_memory (default: 0)

Prevents accidental writes during script execution within a share, and is used only for internal debugging.
Opcache.mmap_base (default: None)

Shared Memory Segment Mapping basics (Windows only). All PHP processes must be mapped to the same shared memory address space. This instruction is used to manually fix the "unable to reattach to base" error.

Opcache expansion under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.