Opcache installation configuration and link effective configuration

Source: Internet
Author: User
Tags fpm zts

First, the principle of Opcache

Second, Opcache installation

Three, Opcache configuration instructions

Iv. Opcache Loading takes effect

Five, Opcache soft link release effective


1.OPCAHCE principle

Optimizer+ is the first and fastest opcode caching tool for Zend developed closed-source, but free-to-use PHP optimization acceleration components. Now, Zend technology company will optimizer+ under PHP License open source becomes Zend Opcache.

The Zend Opcache provides faster PHP execution through opcode caching and optimization. It stores precompiled script files in shared memory for later use, avoiding the time consuming of reading code from disk and compiling it. It also applies some code optimization patterns to make code execution faster.


2.opcahe Installation

In PHP 5.5, 5.6 version Opcache has been built, compile and install the use of--enable-opcache. Check that you have installed the following:

php-m | grep "Zend Opcache"

If it is not installed, install it as follows:

CD PHP-5.6.17CD ext/opcache//usr/local/php5/bin/phpize./configure--with-php-config=/usr/local/php5/bin/ Php-configmakemake Install

3.opcache Configuration

[opcache]zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/opcache.so  ; The code is no longer optimized when the  Zend Optimizer +  switch,  off .opcache.enable=1  ; determines  if zend opcache is enabled for the cli version of  phpopcache.enable_cli=1  ; zend optimizer +  the size of the shared memory,  the total number of precompiled  php that can be stored   Code (in MB), according to the memory to set the opcache.memory_consumption=256  ; zend optimizer +  The total memory of the string in the staging pool. (in MB);  recommended  8opcache.interned_strings_buffer=4  ;  maximum number of cached files  200   to  100000 ;  recommended  4000~8000opcache.max_accelerated_files=8000  ;  memory "waste" When this value corresponds to a percentage, a restart schedule is initiated .opcache.max_wasted_percentage=5  ;  the command is opened, 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.use_cwd=0   ;  Open file Timestamp validation  oPCACHE.VALIDATE_TIMESTAMPS=1  ; 2S Check for file updates   Note: 0 is always checked not off;  recommended   60opcache.revalidate_freq=0  ;  allows or disables the optimization of file searches in  include_path ; opcache.revalidate_path =0    ;  whether to save comments on File/function     if Apigen, Doctrine,  ZF2,  phpunit need file comment ;  recommended  0opcache.save_comments=1  ;  whether to load file/function comments;opcache.load_comments=1     ;  Open Quick Close,  Open this php request shutdown will increase the memory speed will improve;  recommended  1opcache.fast_ shutdown=1  ; allows the optimization of file presence (file_exists, etc.) to be overwritten. ;opcache.enable_file_override=0    ;  defines how many optimization processes to start; opcache.optimization_level= 0xffffffff    ;  enable this hack can temporarily resolve the "can ' T redeclare class" error.; o pcache.inherited_hack=1  ;  enable this hack can temporarily resolve the "can ' T redeclare class" error.; o pcache.dups_fix=0  ;  setting does not cache the blacklist;  does not cache PHP files that begin with cache_ in the specified directory.  /png/www/example.com/public_ html/cache/cache_ ;opcache.blacklist_filename=    ;  the cache of large files through the file size screen. By default, all files are cached.; o pcache.max_file_size=0  ;  Check cache checksum per  N  request. The default value of 0 indicates that the check is disabled.;   Due to the calculation of the checksum damage performance, this directive should be opened at the time of development and debugging. O pcache.consistency_checks=0  ;  after the cache is not accessed, wait for how long (in seconds) to schedule the restart;opcache.force_restart_timeout=180   ;  error log file name. Blank indicates the use of standard error output (stderr).; o pcache.error_log=/tmp/ckl.log  ;  writes error messages to the server (Apache, etc.) log;opcache.log_verbosity_level=1   ;  the preferred background for memory sharing. Leave the system selected.; o pcache.preferred_memory_model=  ;  prevents a share from being accidentally written during script execution,  only for internal debugging.; o Pcache.protect_memory=0

Your own configuration is as follows:

[opcache]zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/opcache.soopcache.enable= 1opcache.memory_consumption=256opcache.interned_strings_buffer=4opcache.max_accelerated_files=8000opcache.max_ Wasted_percentage=5opcache.use_cwd=1opcache.validate_timestamps=1opcache.revalidate_freq=0opcache.revalidate_ path=0opcache.save_comments=0opcache.load_comments=0opcache.force_restart_timeout=3600

4.opcache Loading takes effect

After the configuration is complete, reload PHP process reload

/ETC/INIT.D/PHP-FPM reloadkill-pid 22222 not found PID do

The load at this time does not take effect, because the PID cannot be found, do not need to restart, do the following:

/usr/local/php5/sbin/php-fpm-t[07-jun-2016 14:56:02] Notice:configuration file/usr/local/php5/etc/php-fpm.conf Test is SUCCESSFULKILL-USR2 ' Ps-ef | grep php-fpm | grep Master | awk ' {print $} '

Verify that Opcache is in effect, not through php-i, but by viewing the info page

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/7B/wKiom1dWdqPAp6iJAAA30G_24xM306.png-wh_500x0-wm_3 -wmp_4-s_2736858416.png "title=" Op1.png "alt=" Wkiom1dwdqpap6ijaaa30g_24xm306.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/82/7A/wKioL1dWd7_wmyGSAABNTyfKmxI102.png-wh_500x0-wm_3 -wmp_4-s_1678362711.png "title=" Op2.png "alt=" Wkiol1dwd7_wmygsaabntyfkmxi102.png-wh_50 "/>

5.opcache Soft link Release takes effect

After the new code is released, the new code is connected, and the OPCAHCE cache causes the connection to not take effect, as follows:

Nginx configuration file:

server {    listen        80;    server_name www.kkk.com;    root /data/ ckl-frontend/;    index index.php index.html index.htm;     error_log /usr/local/log/nginx/www.error.log;    location ~ \.php$  {        root /data/ckl-frontend;         fastcgi_pass 127.0.0.1:9000;         Fastcgi_index index.php;        fastcgi_param script_ filename  $document _root$fastcgi_script_name;        include  fastcgi_params;    }} 
Access directory: Ls-l/data/lrwxrwxrwx 1 root root 7 15:10 ckl-frontend-/app/data/ckl/when publishing, create a new directory, generate a new connection

View page:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/82/7A/wKioL1dWeDKCqr2uAAA9ucx4E0I355.png-wh_500x0-wm_3 -wmp_4-s_3124235402.png "title=" Chun.png "alt=" Wkiol1dwedkcqr2uaaa9ucx4e0i355.png-wh_50 "/>

The simulation now publishes the new code:

# cd/app/data/# Cp-a ckl/zld# vim ckl.php <?php$ckl= "Summer"; Echo $ckl;? ># ln-s/app/data/zld/ckl-frontendls-l/data/lrwxrwxrwx 1 root root June 7 15:14 Ckl-frontend-/app/da ta/zld/

Visit page:

Multiple refreshes, still unchanged:

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/82/7B/wKiom1dWd0KRFpMWAABHqYvoPhE539.png-wh_500x0-wm_3 -wmp_4-s_3450000403.png "title=" Chun1.png "alt=" Wkiom1dwd0krfpmwaabhqyvophe539.png-wh_50 "/>


Modification Method:

Modify the following two lines:

Fastcgi_param script_filename $realpath _root$fastcgi_script_name;fastcgi_param document_root $realpath _root;
vim ckl.confserver {    listen       80;     server_name www.kkk.com;    root /data/ckl-frontend/;     index index.php index.html index.htm;    error_log  /usr/local/log/nginx/www.error.log;    location ~ \.php$ {         root /data/ckl-frontend;         fastcgi_pass 127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param script_filename $ Realpath_root$fastcgi_script_name;        fastcgi_param document_ root  $realpath _root;         #fastcgi_param  script_filename   $document _root$fastcgi_script_name;        include fastcgi_params;    }} 

Reload the configuration:

/etc/init.d/nginx Reload

View Page access:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/82/7B/wKiom1dWd5jR1lyAAAA8kVxXg5o450.png-wh_500x0-wm_3 -wmp_4-s_1710313490.png "title=" Su.png "alt=" Wkiom1dwd5jr1lyaaaa8kvxxg5o450.png-wh_50 "/>

This article is from the "take a deep Breath again" blog, make sure to keep this source http://ckl893.blog.51cto.com/8827818/1786964

Opcache installation configuration and link effective configuration

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.