Home > Backend Development > PHP Tutorial > Implementation steps for PHP cache optimization using memcached and xcache

Implementation steps for PHP cache optimization using memcached and xcache

php中世界最好的语言
Release: 2023-03-17 18:52:02
Original
1930 people have browsed it

We know that eaccelerator is a free and open source PHP accelerator that optimizes and dynamic content caching, can improve PHP's script caching performance, and plays an optimization role in scripts, so that your PHP program code execution efficiency can be improved by 1-10 Times, today I will teach you how to optimize caching in PHP.

2. Caching principle

When a user requests a PHP program, the PHP engine will parse the program and compile it into a specific operation code (opcode), which is a Executable code in binary format. This opcode is then executed by the PHP engine and discarded. The opcode cache will save this compiled opcode and reuse it the next time the page is called, thus saving a lot of time on repeated compilation, saving resources, and optimizing performance.
3. Install eaccelerator

Adjust Character set

#echo 'LC_ALL=C' >> /etc/profile#source /etc/profile
[root@~]#tar jxf eaccelerator-0.9.6.tar.bz2[root@~]#cd eaccelerator-0.9.6
[root@~]#/usr/local/php/bin/phpize
phpize是用来扩展php模块的,通过phpize可以建立php的外挂模块[root@~]#./configure --enable-eaccelerator=shared \
--with-php-config=/usr/local/php-5.3.27/bin/php-config[root@~]#make && make install
[root@~]# ls /usr/local/php-5.3.27/lib/php/extensions/no-debug-zts-20090626/eaccelerator.so
Copy after login

4. Configure PHP to load eaccelerator

Create cache directory

mkdir /tmp/eaccelerator #The directory can be stored using tmpfs memoryFile system, SSD solid state drive

chown -R www.www /tmp/eaccelerator
Copy after login

Add the following content in php.ini:

eaccelerator cache config by Zhang DeJin 2017-12-1
[eaccelerator]
extension = eaccelerator.so
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.chech_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_perid="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
--End config
测试:[root@lnmp nginx]# /usr/local/php-5.3.27/bin/php -v
PHP 5.3.27 (cli) (built: Nov 30 2017 05:35:00)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerat
Copy after login

Configuration completed

Restart httpd or php-fpm to take effect

5. Version selection

php5.3.xx available eaccelerator-0.9.6 version
php5.2.xx available eaccelerator-0.9.5.2 version

2)Xcache

1Introduction

XCache is a fast and stable PHP opcode cache. After Well tested and runs stably on high traffic/high load production machines. Tested (on linux) and supports the latest releases of all current PHP branches, such as PHP_4_3 PHP_4_4 PHP_5_0 PHP_5_1 PHP_5_2 HEAD(6.x), and supports Thread-safe/Windows. Better than similar opcode caches, such as the ability to quickly follow PHP versions. The XCache project is led by mOo, who is also a member of the development team of Lighttpd. Lighttpd is one of the fastest web server applications , and outperforms Apache and many other web servers. #

tar jxf xcache-1.3.2.tar.bz2cd xcache-1.3.2/usr/local/php-5.3.27/bin/phpize./configure --enable-xcache --with-php-config=/usr/local/php-5.3.27/bin/php-configmake && make install
ls /usr/local/php-5.3.27/lib/php/extensions/no-debug-zts-20090626/
Copy after login

Modify xcache-1.3.2/xcache.ini, you can use the sed command to modify it

Comment the third line

cd /usr/local/php/lib/
Copy after login


Comment the sixth line

echo >> php.ini
echo "xcache config by ZhangDejin 2017-12-1"
Copy after login


Enable the eighth line

zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
Copy after login


Adjust the remaining parameters according to the server configuration

Then add to php.ini


zend_extension_ts = c:/php/extensions/php_xcache.dll
Copy after login

Test


;extension = xcache.so
Copy after login

Restart httpd or php-fpm to take effect

3) memcache client, PDO_mysql, imagick extension library


1. Introduction

Memcache is a high-performance distributed memory object

Cache system

. By maintaining a unified huge hash table in the memory, it can be used to store data in various formats, including Images, video files and the results of database retrieval, simply put, call the data into the memory and then read it from the memory, thus greatly improving the reading speed

PDO extension defines a database for PHP access A lightweight, consistent interface that provides a data access abstraction layer so that no matter what database is used, you can execute queries to obtain data through consistent functions

ImageMagick is a powerful and stable set of Moreover, the free working set and development kit can change the size, rotate, sharpen, reduce color, etc. of image types in more than 89 formats. Now its main focus is on performance, reducing bugs and providing stable API and ABI. Up

2. Installation

cat /home/king/xcache-1.3.2/xcache.ini >> php.ini
Copy after login
View nginx compilation parameters

nginx -V

View httpd compilation parameters

cat httpd/build/config.nice

View mysql Compilation parameters

grep "CONFIGURE_LINE" mysql/bin/mysqlbug

php Compilation parameters

php/bin/php -i|grep configure

Complete




I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:


Answers to questions about camel case naming and JS

Boolean values, relational operators in JS, Detailed explanation and examples of logical operators


## Summary of the front-end js framework and explanation of its uses

The above is the detailed content of Implementation steps for PHP cache optimization using memcached and xcache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template