Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure eAccelerator and XCache extensions to speed up the execution of PHP programs

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to configure eAccelerator and XCache extensions to accelerate the execution of PHP programs". In daily operations, I believe many people have doubts about how to configure eAccelerator and XCache extensions to speed up the execution of PHP programs. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to configure eAccelerator and XCache extensions to speed up the execution of PHP programs". Next, please follow the editor to study!

Eaccelerator installation and configuration of PHP acceleration

Introduction to eAccelerator

EAccelerator is a free, open source PHP module that provides PHP acceleration, optimization, coding, and dynamic content caching. It speeds up the execution of the PHP script by storing the compiled state of the PHP script without frequently compiling the PHP script. And it optimizes PHP scripts to speed up the execution of PHP. EAccelerator features reducing server load and making PHP scripts 1-10 times faster.

Download address: http://sourceforge.net/projects/eaccelerator/

Decompress and modify the source code (to solve errors such as open_basedir, etc.)

# 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 to

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

Compile and install extension eaccelerator

# / usr/local/php-5.2.14/bin/phpize # corresponding to your own phpize, be sure to execute #. / configure-enable-eaccelerator\-with-php-config=/usr/local/php-5.2.14/bin/php-config# make# make install # in the eaccelerator-0.9.6 directory. It will prompt you which directory the extension is loaded to. On my side is / usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/.

Configure php.ini

If the machine has added an extension before, skip to the next step, "add eacclerator extension"

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

Set

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

[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 the test

Restart apache or nginx, and check the results. If there is a directory under / tmp/eaccelerator, the installation is successful.

Configuration parameters detailed explanation (eaccelerator)

Eaccelerator.shm_size= "8"

The amount of shared memory (in megabytes) that can be used by eAccelerator. "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, and it is OK to have 8pint 16pint 32pr 64128.

Eaccelerator.cache_dir= "/ tmp/eaccelerator"

This directory is for disk cache use. EAccelerator stores precompiled code, process data, content, and user-defined content here. The same data can also be stored in shared memory (which improves access speed). The default setting is / tmp/eaccelerator.

Eaccelerator.enable= "1"

Turns eAccelerator on or off. "1" is on and "0" is off. The default value is "1".

Eaccelerator.optimizer= "1"

Turn on or off the internal optimizer to speed up code execution. "1" is on and "0" is off. The default value is "1".

Eaccelerator.check_mtime= "1"

Turns PHP's file modification check on or off. "1" means on and "0" means off. If you recompile the PHP file after modification, you should set it to "1". The default value is "1".

Eaccelerator.debug= "0"

Turns debug logging on or off. "1" is on and "0" is off. The default value is "0". The cache hit record is written to the log.

Eaccelerator.filter= ""

Determine which PHP files must be cached. You can specify cached and non-cached file types (such as "* .php * .phtml", etc.) if the parameter is "!" At the beginning, files that match these parameters are ignored. The default value is ", that is, all PHP files will be cached.

Eaccelerator.shm_max= "0"

When using the "eaccelerator_put ()" function, it is prohibited from storing large files in shared memory. This parameter specifies the maximum value allowed to be stored in bytes (10240, 10K, 1m). "0" is unlimited. The default value is "0".

Eaccelerator.shm_ttl= "0"

When eAccelerator fails to get the shared memory size of the new script, it removes all script caches that were not accessed in the last "shm_ttl" second from the shared memory. The default value is "0", that is, no cache files are deleted from the shared inner spring.

Eaccelerator.shm_prune_period= "0"

When eAccelerator fails to get the shared memory size of the new script, he will try to remove cached scripts that are earlier than "shm_prune_period" seconds from the shared memory. The default value is "0", that is, no cache files are deleted from the shared inner 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", that is, using disk and shared memory for caching.

Eaccelerator.compress= "1"

Allows or disables compressed 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 is "9", which is the highest level.

Eaccelerator.keys = "disk_only" eaccelerator.session = "disk_only" eaccelerator.content = "disk_only"

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

Shm_and_disk is sharing 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 will be saved to the hard disk.

Shm_only is 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 the opcode generated by php runtime compilation to accelerate the efficiency of the php program. Installing xcache is similar to installing memcache, which is installed as an extension. Any extension method of PHP is basically as follows, so you don't need to look for xxx extension documents.

Install the 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

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 to this directory

Edit php profile

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

Overload PHP

# service php-fpm reload

If you are in Apache+PHP mode, then restart Apache.

# service httpd restart

Or

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

Test result

At this point, the study on "how to configure eAccelerator and XCache extensions to accelerate the execution of PHP programs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report