PHP ~ Compare with the performance of various acceleration tools ~. Xcache has previously introduced the principles and functions of the PHP accelerator (see the PHP-FPM server of LAMP architecture), xcache as one of the currently widely used PHP accelerators, its performance than the early Xcache introduction
I have already introduced the principles and functions of the PHP accelerator (see PHP-FPM server in LAMP architecture). as one of the widely used PHP accelerators, xcache has better performance than the early eAccelerator accelerators, therefore, this article compares the performance impact of the accelerator xcache on PHP programs during execution.
Install xcache
# Installation
Tar xf xcache-3.0.3.tar.gz
Cd xcache-3.0.3
/Usr/local/php/bin/phpize # xcache is installed as an external php module.
./Configure -- enable-xcache -- with-php-config =/usr/local/php/bin/php-config
Make & make install
# The following lines will appear at the end of installation:
Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
# Edit php. ini and integrate php and xcache:
# First import the sample configuration provided by xcache to php. ini
Mkdir/etc/php. d # This is the configuration file scan directory configured during PHP installation.
The cp xcache. ini/etc/php. d # xcache. ini file is in the xcache source code directory.
# Edit/etc/php. d/xcache. ini, find the line starting with extension, and change it to the following line:
Extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache. so
# If the php. ini file contains multiple extension command lines, make sure that the new lines are ranked first.
# Check whether xcache has been installed successfully:
/Usr/local/php/bin/php-m | grep-I xcache
Introduction to Opcache
The new-generation PHP accelerator, developed by Zend, is implemented in a similar way as Xcache. it caches the executed PHP Data to the memory to avoid repeated compilation processes, you can directly use the compiled code in the buffer zone to increase the speed and reduce the server load, but the performance is superior to that of Xcache. for details, see the test results.
Install Opcache
Wget http://pecl.php.net/get/zendopcache-7.0.2.tgz
Tar xzf zendopcache-7.0.2.tgz
Cd zendopcache-7.0.2
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make
Make install
# Configuration file settings, which can be directly configured in php. add the following content at the end of ini, but in the PHP configuration file's scan directory php. d. configure the new file opcache. ini, which is easy to manage. php-config-scan-dir is defined during PHP compilation and installation.
# Vi/etc/php. d/opcache. ini
[Opcache]
Zend_extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/opcache. so
Opcache. memory_consumption = 128 # Size of allocated memory, in MB, that is, the amount of pre-compiled PHP code that can be stored
Opcache. interned_strings_buffer = 8 # memory size occupied by interned strings, in MB
Opcache. max_accelerated_files = 4000 # maximum number of files that can be cached
Opcache. revalidate_freq = 60 # How long does it take to check the file timestamp to change the shared memory allocation, in seconds?
Opcache. fast_shutdown = 1 # enable and disable the queue function quickly.
Opcache. enable_cli = 1 # allow caching PHP programs under CLI
# Check whether the module is successfully installed:/usr/local/php/bin/php-m | grep-I opcache
About hhvm
HipHop VM (HHVM) is a virtual machine launched by Facebook to execute PHP code. it is a php jit (Just-In-Time) compiler, at the same time, it has the advantages of fast code generation and instant compilation;
Hhvm converts PHP code compilation into a C ++ program for execution, significantly improving the execution efficiency;
According to Facebook, HHVM has made significant improvements in speed, which is 60% faster than the current PHP interpreter and 90% less than memory usage.
Install hhvm
At present, hhvm is still in the R & D stage. there are few domestic production environments and the environment required for installation is complicated (for example, boost-system and boost-filesystem Versions under CentOS6.5 are too low ), therefore, I am still in the debugging and testing phase, wait for the test results, and then paste the hhvm test results together.
Test Procedure
# Find another virtual machine to perform stress testing on the HTTPD server (192.168.1.110)
# Use the benchmark test tool AB provided by Apache.
# The test method is as follows:
AB-c 20-n 2000 http: // 192.168.1.110: 8080/index. php
# Note: The test uses 20 concurrent threads. you can view the acceleration effect of the xcache accelerator without affecting access. on the test page, use index. php on the logon page of phpMyAdmin just deployed.
# Note: In order to better test the cache feature of the PHP accelerator, you can test it several times in a row to obtain a stable value.
The principles and functions of the PHP accelerator (see the PHP-FPM server of LAMP architecture), xcache is one of the widely used PHP accelerators, and its performance is better than that of the earlier ones...