Home  >  Article  >  Backend Development  >  Configure eAccelerator and XCache extensions to accelerate the execution of PHP programs, _PHP Tutorial

Configure eAccelerator and XCache extensions to accelerate the execution of PHP programs, _PHP Tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:40765browse

Configure eAccelerator and XCache extensions to accelerate the execution of PHP programs,

eaccelerator installation and configuration PHP acceleration
Introduction to eAccelerator
eAccelerator is a free, open source PHP module that provides PHP acceleration, optimization, encoding, and dynamic content caching functions. It speeds up the execution of PHP scripts by storing the compiled state of the PHP script without the need to compile the PHP script frequently. And it can optimize PHP scripts to increase the speed of executing PHP. The feature of eAccelerator is that it reduces the server load and accelerates PHP scripts by 1-10 times.
Download address: http://sourceforge.net/projects/eaccelerator/
Unzip and modify the source code (solve errors such as open_basedir)

# tar jxvf eaccelerator-0.9.6.tar.bz2
# cd eaccelerator-0.9.6/
# vi eaccelerator.c

Found the following:

if (PG(open_basedir) && php_check_open_basedir(realname TSRMLS_CC)) {

changed to

if (PG(open_basedir) && php_check_open_basedir(file_handle->filename TSRMLS_CC)) {

Compile and install the extension eaccelerator

# /usr/local/php-5.2.14/bin/phpize # 对应你自己的phpize,一定要在eaccelerator-0.9.6目录执行
# ./configure
–enable-eaccelerator \
–with-php-config=/usr/local/php-5.2.14/bin/php-config
# make
# make install # 会提示你扩展装到了哪个目录,我这边是/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/

Configure php.ini
If an extension has been added to this machine before, jump directly to the next step "Add eacclerator extension"

Vi /usr/local/php-5.2.14/etc/php.ini

will

extension_dir = ./
Replace

with

extension_dir=/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/

Add eacclerator extension

# vi /usr/local/php-5.2.14/etc/php.ini

Add the following content

 [eaccelerator]
 extension=eaccelerator.so
 eaccelerator.shm_size=”16″
 eaccelerator.cache_dir=”/tmp/eaccelerator”
 eaccelerator.enable=”1″
 eaccelerator.optimizer=”1″
 eaccelerator.check_mtime=”1″
 eaccelerator.debug=”0″
 eaccelerator.filter=””
 eaccelerator.shm_max=”0″
 eaccelerator.shm_ttl=”0″
 eaccelerator.shm_prune_period=”0″
 eaccelerator.shm_only=”0″
 eaccelerator.compress=”1″
 eaccelerator.compress_level=”9″

Create eaccelerator directory

# mkdir /tmp /eaccelerator
# chmod 777 /tmp/eaccelerator

Restart testing
Restart apache or nginx and check the effect. If there is a directory under /tmp/eaccelerator, the installation is successful.
Detailed explanation of configuration parameters (eaccelerator)

eaccelerator.shm_size=”8″

The amount of shared memory that eAccelerator can use (in megabytes). "0" refers to the default value of the operating system. The default value is "0". It can be adjusted according to the actual situation of the server, 8, 16, 32, 64, 128 is fine.
eaccelerator.cache_dir=”/tmp/eaccelerator ”

This directory is used for disk caching. eAccelerator stores precompiled code, process data, content and user-defined content here. The same data can also be stored in shared memory (this can improve access speed) . The default setting is "/tmp/eaccelerator".

eaccelerator.enable=”1″

Turn eAccelerator on or off. "1" means on, "0" means off. The default value is "1".

eaccelerator.optimizer=”1″

Enable or disable the internal optimizer to improve code execution speed. "1" means on, "0" means off. The default value is "1".

eaccelerator.check_mtime=”1″

Turn on or off PHP's file modification check. "1" means on, "0" means off. If you recompile PHP files after modification, then you should set it to "1". The default value is " 1”.

eaccelerator.debug=”0″

Turn debug logging on or off. "1" means on, "0" means off. The default value is "0". Records of cache hits will be written to the log.

eaccelerator.filter=””

Determine which PHP files must be cached. You can specify cached and non-cacheable file types (such as "*.php *.phtml", etc.). If the parameters start with "!", files matching these parameters will be ignored from the cache. The default value is "", i.e. all PHP files will be cached.

eaccelerator.shm_max=”0″

When using the "eaccelerator_put()" function, it is prohibited to store files that are too large into shared memory. This parameter specifies the maximum value allowed to be stored, in bytes (10240, 10K, 1M). "0" means no limit. The default value is "0".

eaccelerator.shm_ttl=”0″

When eAccelerator fails to obtain the shared memory size for a new script, it will delete all script caches from shared memory that have not been accessed in the last "shm_ttl" seconds. The default value is "0", which means no cache files are deleted from the share.

eaccelerator.shm_prune_period=”0″

When eAccelerator fails to obtain the shared memory size for a new script, it will attempt to remove cached scripts older than "shm_prune_period" seconds from shared memory. The default value is "0", which means no cache files are deleted from the share.

eaccelerator.shm_only=”0″

Allow or disable caching of compiled scripts on disk. This option has no effect on session data and content caching. The default value is "0", which means: use disk and shared memory for caching.

eaccelerator.compress=”1″

Allow or disable caching of compressed content. The default value is "1", which means compression is allowed.

eaccelerator.compress_level=”9″

Specify the compression level for content caching. The default value is "9", the highest level.

eaccelerator.keys = “disk_only”
eaccelerator.session = “disk_only”
eaccelerator.content = “disk_only”

Set the storage location of the content cache, which can be set to:

  • shm_and_disk on shared cache and disk (default)
  • shm exists in shared memory by default. If the shared memory is full or the size exceeds the value of "eaccelerator.shm_max", it will be saved to the hard disk
  • shm_only is only stored in shared memory
  • disk_only only stored in hard disk
  • none does not cache data

PHP extension xcache installation
The xcache module can cache the opcode generated by PHP runtime compilation, which can speed up the efficiency of PHP programs. The method of installing xcache is similar to that of installing memcache. They are both installed in an extended manner. Any extension method for PHP is basically as follows, so no need I specifically looked for the documentation for the xxx extension.
Install PHP extension xcache

# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
# tar -xvf xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# ./configure –with-php-config=/usr/local/php/bin/php-config –enable-xcache
# make && make install

It will generate information similar to the following

Installing shared extensions:  /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

All modules will be generated in this directory
Edit php configuration file

# vim /usr/local/php/etc/php.ini
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

Reload PHP

# service php-fpm reload

If you are in Apache PHP mode, just restart Apache.

# service httpd restart

or

# /usr/local/apache-2.2.27/bin/apachectl restart

Test results

20151222144250527.png (603×475)

Articles you may be interested in:

  • Notes on installing PHP xcache extension module under CentOS 6.3
  • Specific steps for compiling and installing xcache for php5.3 under ubuntu
  • PHP Accelerator eAccelerator Configuration and Usage Guide

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084565.htmlTechArticleConfigure eAccelerator and XCache extensions to accelerate the execution of PHP programs, eaccelerator installation and configuration PHP acceleration eAccelerator introduction eAccelerator is a free , open source PHP module, which can...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn