PHP Enable cache acceleration

Source: Internet
Author: User
Tags php source code zts zend

PHP defaults to discard the operate code file, cache acceleration is saved, placed in shared memory, to be reused the next time the PHP page is invoked, to avoid duplicate compilation of the same Code

___________________________________________________________

Lamp Environment PHP Parsing principle
___________________________________________________________
Apache receives the client's PHP program request and filters it according to the rules
Apache passes the PHP program request to the PHP processing module libphp5.so
The PHP engine locates the PHP file on the disk and loads it into memory for parsing
PHP processing module libphp5.so PHP source code compiled into opcode
The PHP processing module libphp5.so executes opcode and then caches the opcode.
Apache receives a new PHP program request from the client, the PHP engine reads the cache directly to execute the opcode file, and returns the result

LNMP Environment PHP Parsing principle
___________________________________________________________
Nginx receives the client's PHP program Access request
Nginx passes PHP program requests to the FCGI (PHP FPM) process that parses PHP based on filtering rules such as extensions
PHP fpm Process calls PHP parser to read PHP file on site disk and load into memory
The PHP parser compiles the PHP program into a opcode file and then caches the opcode.
PHP fpm engine executes opcode tree, returns data to Nginx, and returns to client
Nginx receives a new PHP program request from the client, the PHP fpm engine reads the opcode in the cache and executes it, returning the result

Cache acceleration Plug-in installation configuration (XCache)
___________________________________________________________

  1. [Root@Web_server src]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2 
  2. [Root@Web_server src]# tar XF xcache-3.2.0.tar.bz2  
  3. [Root@Web_server src]# cd xcache-3.2.0  
  4. [Root@Web_server xcache-3. 2. 0]#/usr/local/php/bin/phpize     
  5. [Root@Web_server xcache-3. 2. 0]      
  6. [Root@Web_server xcache-3. 2. 0]# make && make install     
  7. [Root@Web_server xcache-3. 2. 0]# ll/usr/local/php/lib/php/extensions/ no-debug-non-zts-20121212/     
  8. 2208
  9. -RWXR-xr:opcache. A    
  10. -RWXR-xr1 root root  :opcache.      so
  11. -RWXR-xr1 root  :xcache#<== generate xcache.so module     
  12. [Root@Web_server xcache-3. 2. 0]# Cat/usr/local/src/xcache-3.2.0/xcache.ini >>/ Usr/local/php/etc/php.ini     
  13. [Root@Web_server xcache-3. 2. 0]# Tail-85/usr/local/php/etc/php.ini | egrep-v "^;|^$" 
  14. [XCache-common] 
  15. = XCache. so
  16. [XCache. Admin] 
  17. XCache. Admin=  on
  18. XCache. Admin"MOo" 
  19. XCache. Admin"MD5 encrypted password" 
  20. [XCache]
  21. XCache=        "mmap" 
  22. XCache. Size  =               256M 
  23. XCache.  =                 2  
  24. XCache=                8K
  25. XCache. TTL   =                 86400  
  26. XCache=          3600 
  27. XCache. var_size  =            64M 

#更改标红参数, the production environment adjusts to hardware and business data

  1. [Root@Web_server xcache-3. 2. 0]#/usr/local/php/bin/php-v #检查配置  
  2. PHP 5. 5(CLI(built: +)        
  3. (c1997-ThePHP Group  
  4. Zend Engine v2. 5. 0(C1998-Zend Technologies     
  5. With XCache v3. 2. 0(C2005-up, by MOo      
  6. With XCache Cacher v3. 2. 0(C2005-up, by MOo      
  7. [Root@Web_server ~]# echo-n "Szk" |md5sum  
  8. [Root@Web_server ~]# vim/usr/local/php/etc/php.ini   #配置xcache用户密码 
  9. XCache. Admin"Szk" 
  10. XCache. Admin"005EFF7DD9626F0C30F2EB8003CEAFC9" 
  11. [Root@Web_server ~]# cp-a/usr/local/src/xcache-3.2.0/htdocs//data/www/xadmin  
  12. [Root@Web_server ~]# chown-r nobody.nobody/data/www/xadmin  
  13. [Root@Web_server ~]#/etc/init.d/php-fpm start  

Cache acceleration Plug-in installation configuration (Opcache)
___________________________________________________________
#若5. Version 5, the Opcache plugin is automatically installed and--enable=opcache enabled at compile time

  1. [Root@Web_server ~]#  ll/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/  
  2. -RWXR-xr1 root root  :opcache.      so
  3. [Root@Web_server ~]# Vim/usr/local/php/etc/php.ini  #若编译没有启用, add the following to the configuration file  
  4. Zend_extension=opcache.  So
  5. [Opcache]
  6. Opcache. memory_consumption=  
  7. Opcache. Interned_strings_buffer=8  
  8. Opcache. Max_accelerated_files=4000  
  9. Opcache. Revalidate_freq=  
  10. Opcache. Fast_shutdown=1  
  11. Opcache. Enable=1  
  12. Opcache. Enable_cli=1  
  13. [Root@Web_server ~]#/usr/local/php/bin/php-v  
  14. PHP 5. 5(CLI(built         : 
  15. (c1997-ThePHP Group  
  16. Zend Engine v2. 5. 0(C1998-Zend Technologies     
  17. With Zend Opcache V7. 0. 6-dev(C1999-$, by Zend Technologies  

PHP Enable cache acceleration

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.