PHP cache plug-in Zend Opcache (replacing APC)
Introduction:
Zend Opcache and APC are PHP code accelerators, which cache the compilation results of PHP source code and compare the time mark when calling again. if no changes are made, cache data is used, this eliminates the overhead of re-parsing code.
APC stops at PHP 5.4, and Zend Opcache is integrated from PHP 5.5 to replace APC.
1. Install Zend Opcache
1. When compiling PHP with source code, add -- enable-opcache to enable the extension, and then configure it later.
2. manually add Zend Opcache extension.
Shell> cd/usr/local/src/php-5.6.17/ext/opcache # Go To The plug-in directory under the PHP source code directory
Shell>/usr/local/php/bin/phpize # generate configure
Shell>./configure -- with-php-config =/usr/local/php/bin/php-config
Shell> make; make install # complete installation
Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
2. Configure Zend Opcache
Shell> vim/usr/local/php. ini
[Opcache] # Find this module
Zend_extension = '/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/opcache. so' # specify the library file
Opcache. enable = 1 # enable Zend Opcache
Opcache. enable_cli = 1 # enable Opcache on the command line
Opcache. memory_consumption = 32 # shared memory size, in MB, set according to the actual situation
Opcache. interned_strings_buffer = 8
Opcache. max_accelerated_files = 4000 # the maximum number of cached files. This limit can be increased when the hit rate is low (4000 is not the whole 4000, but it will be more than this number)
Opcache. revalidate_freq = 60 # Find the file Update Interval
Opcache. save_comments = 0 # Do not save comments of files and functions, which can improve performance. However, some frameworks may have problems. We recommend that you set them after testing! (Saved as 1 by default)
Opcache. fast_shutdown = 1 # enable memory rapid recovery
Shell> service php-fpm restart # Now you can see that Zend Opcache or php-m | grep-I opcache is successfully loaded on the phpinfo interface.
3. Monitor and manage Zend Opcache
Two open-source projects (the second one looks better ):
1. https://github.com/PeeHaa/OpCacheGUI
2. https://github.com/amnuts/opcache-gui
# You can intuitively see the memory usage, hit rate, cached files, and other information!
# The second project is deployed in a single file, which is very convenient. However, you must set the permission for the URL.
Shell> unzip opcache-gui-master.zip
Shell> mkdir/data/www/opcache; cp opcache-gui-master/index. php/data/www/opcache/
Shell> vim/usr/local/nginx/conf/nginx. conf
Location ~ /Opcache/index. php {# Add the configuration to server {}. You can use. * opcache. * to replace/opcache/index. php
Access_log off;
Allow 127.0.0.1;
Allow 36.110.41.194; # Only allow access from an IP address
Deny all;
Location ~ \. Php $ {# Add resolution to PHP here, otherwise 404 permission denied will be reported
Root/data/www;
Fastcgi_pass 127.0.0.1: 9000;
# Fastcgi_pass unix:/dev/shm/php-cgi.sock; #127.0.0.1: 9000
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/data/www $ fastcgi_script_name;
Include fastcgi_params;
}
}
Shell> kill-HUP 'cat/usr/local/nginx/logs/nginx. pid'
# Visit http: // IP/opcache/index. php in a browser!
# This is Zend Opcache, which is convenient and practical! (The original APC is also pretty good !)
Iv. Stress Testing
Shell> yum-y install siege
Shell> siege-c 100-t 30 s http: // 127.0.0.1/info. php #100 concurrency, test for 30 seconds (example)
Transactions: 5624 hits # Total number of requests
Availability: 100.00% # Success Rate
Elapsed time: 29.56 secs # Total time consumed
Data transferred: 117.17 MB # total Data transmission volume
Response time: 0.01 secs # Response time
Transaction rate: 190.26 trans/sec # average number of requests completed per second
Throughput: 3.96 MB/sec # average data transfer per second
Concurrency: 2.32 # actual maximum number of concurrent connections
Successful transactions: 5624 # Number of Successful processes
Failed transactions: 0 # number of Failed processes
Longest transaction: 0.15 # maximum time of each transmission
Shortest transaction: 0.00 # minimum time for each transmission
Deep understanding of ini configuration in PHP
Analyze the timeout mechanism of PHP scripts
Build a PHP development environment under Ubuntu 14.04 PDF
PHP 7 innovation and Performance Optimization
PHP 7, you deserve it
Experience PHP 7.0 on CentOS 7.x/Fedora 21
Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)
Nginx startup failure occurs during LNMP deployment.
Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)
Detailed php hd scanning PDF + CD source code + full set of teaching videos
Configure the php lnmp development environment in CentOS 6
PHP details: click here
PHP: click here
This article permanently updates the link address: