Configure eAccelerator and XCache extension to accelerate PHP program execution

Source: Internet
Author: User
Tags zts
This article mainly introduces how to configure eAccelerator and XCache extension to accelerate the execution of PHP programs. XCache and ZendOpcache that come with PHP5.5 are the same cache that stores Opcode in the shared memory, for more information, see Install and configure eaccelerator for PHP acceleration
Introduction to eAccelerator
EAccelerator is a free and open-source PHP module that provides PHP acceleration, optimization, Code adding, and dynamic content caching. It accelerates the execution of PHP scripts by storing the status of PHP scripts after compilation, without frequently compiling this PHP script. It can optimize PHP scripts to speed up PHP execution. The eAccelerator feature reduces server load and accelerates PHP scripts by 1-10 times.
: Http://sourceforge.net/projects/eaccelerator/
Decompress and modify the source code (resolving errors such as open_basedir)

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

Find the following:

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

Change

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 # corresponding to your own phpize, must be executed in the eaccelerator-0.9.6 Directory #. /configure-enable-eaccelerator \-with-php-config =/usr/local/php-5.2.14/bin/php-config # make install # will prompt which Directory your extension is installed in, here I am/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/

Configure php. ini
If the local machine has been expanded before, go directly to the next step to "add eacclerator extension"

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

Set

extension_dir = ./

Replace

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 an eaccelerator Directory

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

Restart test
Restart apache or nginx and check the effect. if a directory exists in/tmp/eaccelerator, the installation is successful.
Detailed 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. values 8, 16, 32, 64, and 128 are acceptable.

eaccelerator.cache_dir=”/tmp/eaccelerator ”

This directory is used for disk cache. here, eAccelerator stores pre-compiled code, process data, content, and user-defined content. the same data can also be stored in the shared memory (this can increase the access speed ). the default value is "/tmp/eaccelerator ".

eaccelerator.enable=”1″

Enable or disable eAccelerator. "1" is enabled, and "0" is disabled. The default value is 1 ".

eaccelerator.optimizer=”1″

Enable or disable the internal Optimizer to speed up code execution. "1" is enabled, and "0" is disabled. The default value is 1 ".

eaccelerator.check_mtime=”1″

Open or close the PHP file modification check. "1" indicates opening, and "0" indicates closing. if you re-compile the PHP file after modification, you should set it to "1 ". the default value is "1 ".

eaccelerator.debug=”0″

Enable or disable debugging logging. "1" is enabled, and "0" is disabled. The default value is "0 ". Logs will be written to the cache hit records.

eaccelerator.filter=””

Determine which PHP files must be cached. You can specify the cached and non-cached file types (for example, "*. php *. phtml"). Files that match these parameters are ignored. The default value is "", that is, all PHP files will be cached.

eaccelerator.shm_max=”0″

When the "eaccelerator_put ()" function is used, it is prohibited to store excessive files in the shared memory. This parameter specifies the maximum value that can be stored, in bytes (10240, 10 K, 1 M ). "0" is unlimited. The default value is "0 ".

eaccelerator.shm_ttl=”0″

When the eAccelerator fails to obtain the shared memory size of the new script, it will delete all script caches that are not accessed in the last "shm_ttl" seconds from the shared memory. The default value is "0", that is, no cached files are deleted from the shared files in the spring.

eaccelerator.shm_prune_period=”0″

When the eAccelerator fails to obtain the shared memory size of the new script, it will try to delete the cache script earlier than "shm_prune_period" from the shared memory. The default value is "0", that is, no cached files are deleted from the shared files in the spring.

eaccelerator.shm_only=”0″

Allow or disable caching compiled scripts on disks. This option is invalid for session data and content caching. The default value is "0", that is, the disk and shared memory are used for cache.

eaccelerator.compress=”1″

Allows or disables content caching. The default value is "1", that is, compression is allowed.

eaccelerator.compress_level=”9″

Specifies the compression level of the content cache. The default value is 9, which is the highest level.

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

Set the location where the content cache is stored. you can set it:

  • Shm_and_disk in shared cache and hard disk (default)
  • Shm has shared memory by default. if the shared memory is full or the size exceeds the value of "eaccelerator. shm_max", it is saved to the hard disk.
  • Shm_only is stored only in the shared memory.
  • Disk_only is stored on the hard disk
  • None

PHP extension xcache installation
The xcache module can cache the opcode generated during php runtime to accelerate the efficiency of the php program. the method for installing xcache is similar to that for installing memcache. it is installed in an extended way, any PHP extension method is basically as follows, so you do not need to look for xxx extension documentation.
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

The following information is generated:

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

All modules are generated under this directory.
Edit the php configuration file

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

Heavy load PHP

# service php-fpm reload

If you are using Apache + PHP, restart Apache.

# service httpd restart

Or

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

Test results

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.