This article mainly introduces the differences and selection suggestions of eAccelerator, memcached, xcache, APC, and other four acceleration and cache extensions in PHP. if you need them, you can refer to your VPS colleagues, after LNMP and other Web runtime environments are installed, some cache extension installation will be selected to speed up PHP running, what are the differences between eAccelerator, memcached, xcache, and Alternative PHP Cache? What are their respective roles? How do we choose? This is the answer provided in this article.
1. eAccelerator
EAccelerator is a free and open source PHP accelerator. It optimizes and dynamically caches content, improves the cache performance of PHP scripts, and completely eliminates the server overhead when PHP scripts are compiled. It also optimizes scripts to accelerate execution efficiency. This improves the code execution efficiency of PHP programs by 1-10 times. The text can be understood as: eAccelerator is a PHP accelerator extension.
2. memcached
Memcached is a high-performance distributed memory object cache system for dynamic Web applications to reduce database load. It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed. It can be understood from the text as: memory cache expansion, which is mainly used for distributed caching for cluster servers.
3. Alternative PHP Cache (APC Cache)
Alternative PHP Cache (APC Cache) is an effective open-source high-speed buffer storage tool for PHP. it can Cache the PHP intermediate code of Opcode (target file. APC cache consists of system cache and user data cache. the system cache is automatically used. it means that APC caches the compilation result of the PHP file source code and compares the time Mark when calling the php file again. If it has not expired, use the cache code to run it. The default cache is 3600 s (one hour ). however, this will still waste a lot of CPU time. therefore, you can. set system cache in ini to never expire (apc. ttl = 0 ). however, after the PHP code is modified, you need to restart your web server (such as apache ...). Currently, the performance test of APC generally refers to this layer of cache. from text to Alternative PHP Cache (APC cache) is also a memory Cache extension, which is a database cache extension.
4. Xcache
It is an open-source opcode cache/optimizer that can improve the PHP performance on the server. it caches the compiled PHP Data to the shared memory to avoid repeated compilation processes, you can directly use the compiled code in the buffer to increase the speed. generally, it can increase the page generation rate by 2 to 5 times, reducing the server load. It is actually a PHP accelerator extension like eAccelerator.
The above are their roles and differences. The simple point is: eAccelerator, xcache is the PHP Cache extension, and memcached and APC cache are the database cache extensions. Generally, only one of them needs to be installed, don't be greedy. In addition, in actual tests, it is found that when the number of caches exceeds a certain threshold, the performance of APC is inferior to that of Memcache. Therefore, I usually choose xcache + memcached as an extension.