Configure Eaccelerator and XCache extensions to speed up the execution of PHP programs _php techniques

Source: Internet
Author: User
Tags configuration php install php php script zts

Eaccelerator Installation Configuration PHP acceleration
Eaccelerator Introduction
Eaccelerator is a free, open source PHP module that can provide PHP acceleration, optimization, overweight, and dynamic content caching capabilities. It speeds up the execution of PHP scripts by storing the PHP script's compiled state, without the need to compile the PHP script frequently. And it can optimize PHP scripts to improve the speed of PHP execution. The Eaccelerator feature is to reduce the server load and speed up the PHP script by 1-10 Times.
Download Address: http://sourceforge.net/projects/eaccelerator/
Decompression to modify the source code (to resolve the occurrence of open_basedir and other errors)

# 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)) {

To

if (PG (open_basedir) && php_check_open_basedir (File_handle->filename tsrmls_cc)) {

Compile installation Extensions Eaccelerator

#/usr/local/php-5.2.14/bin/phpize # corresponding to your own phpize, be sure to perform in the eaccelerator-0.9.6 directory
#./configure
- Enable-eaccelerator \
–with-php-config=/usr/local/php-5.2.14/bin/php-config # make
# make
Install # will prompt you to extend to which directory, my this is/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/

Configure PHP.ini
If the machine has been extended before, skip to the next "Add eacclerator extension"

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

Will

Extension_dir =./

Replace into

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 Test
Restart Apache or Nginx, and view the effect, if the/tmp/eaccelerator has a directory, the installation is successful.
Detailed configuration parameters (Eaccelerator)

Eaccelerator.shm_size= "8″

Eaccelerator The amount of shared memory that can be used (in megabytes). "0" refers to the default value of the operating system. The default value is "0". can be adjusted according to the actual situation of the server, 8,16,32,64,128 can be.
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 (which can improve access speed). The default setting is "/tmp/eaccelerator".

Eaccelerator.enable= "1″

Turn eaccelerator on or off. "1" is turned on, "0" is closed. The default value is "1".

Eaccelerator.optimizer= "1″

The internal optimizer can be turned on or off to increase code execution speed. "1" is turned on, "0" is closed. The default value is "1".

Eaccelerator.check_mtime= "1″

Turn on or off the file modification check for PHP. "1" means to open, "0" means to close. If you recompile the PHP file after the modification, you should set it to "1". The default value is "1".

Eaccelerator.debug= "0″

Turn debug logging on or off. "1" is turned on, "0" is closed. The default value is "0". Writes a cache hit record to the log.

Eaccelerator.filter= ""

Determine which PHP files must be cached. You can specify the cached and not cached file types (such as "*.php *.phtml", and so on), and if the parameters start with "!", the files that match the parameters are ignored for caching. The default value is "", that is, all PHP files will be cached.

eaccelerator.shm_max= "0″

Prevents large files from being stored in shared memory when the Eaccelerator_put () function is used. This parameter specifies the maximum value that is allowed to be stored, in bytes (10240, 10K, 1M). "0" is not limited. The default value is "0".

Eaccelerator.shm_ttl= "0″

When Eaccelerator fails to get the shared memory size of the new script, it deletes all script caches that were not accessed in the last "Shm_ttl" seconds from the shared memory. The default value is "0", which means that no cached files are deleted from the shared spring.

Eaccelerator.shm_prune_period= "0″

When Eaccelerator fails to get the shared memory size of the new script, he attempts to remove cache scripts older than "Shm_prune_period" from shared memory. The default value is "0", which means that no cached files are deleted from the shared spring.

Eaccelerator.shm_only= "0″

Allows or disables caching of compiled scripts on disk. This option is not valid for session data and content caching. The default value is "0", which is to use disk and shared memory for caching.

Eaccelerator.compress= "1″

Allows or disables the compression of content caching. The default value is "1", which is: Allow compression.

Eaccelerator.compress_level= "9″

Specifies the compression level for 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"

The place where the content cache is stored can be set to:

    • Shm_and_disk in shared cache and hard disk (default)
    • SHM shared memory exists by default, if shared memory is full or size exceeds "Eaccelerator.shm_max" value, save to hard drive
    • shm_only only stored in shared memory
    • Disk_only is only stored on the hard drive
    • None does not cache data

PHP Extended XCache Installation
the XCache module can cache php run-time compilation generated opcode can speed up the efficiency of the PHP program, install XCache and install Memcache method similar to, are installed in an extended manner, php any extension methods are basically the following, So there is no need to look for the XXX extended document specifically.
Install PHP extensions 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

Will generate similar information like the following

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

All modules will be generated into 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

Overload PHP

# Service PHP-FPM Reload

If you are apache+php mode, then 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.