


Implementation steps for PHP cache optimization using memcached and xcache
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
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
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
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/
Comment the third line
cd /usr/local/php/lib/
Comment the sixth line
echo >> php.ini echo "xcache config by ZhangDejin 2017-12-1"
Enable the eighth line
zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
Adjust the remaining parameters according to the server configurationThen add to php.ini
zend_extension_ts = c:/php/extensions/php_xcache.dll
Test
;extension = xcache.so
Restart httpd or php-fpm to take effect
3) memcache client, PDO_mysql, imagick extension library
1. Introduction
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 speedPDO 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 functionsImageMagick 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. Upcat /home/king/xcache-1.3.2/xcache.ini >> php.ini
nginx -V
View httpd compilation parameterscat httpd/build/config.nice
View mysql Compilation parametersgrep "CONFIGURE_LINE" mysql/bin/mysqlbug
php Compilation parametersphp/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
## 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
