Xue Qikang( [email protected] )
The transmission efficiency of commercial application websites is very important. Usually on some e-commerce websites, the response speed of the server determines the quality of its service, and the load of the server determines its maximum access capacity that can be provided to customers. Technicians are always looking for ways to improve server response speed as much as possible. ZendCache is also an excellent product developed to improve the response speed of the server. Data proves that using ZendCache can increase the server's response speed to more than 300% of the original.
1. What is ZendCache
? Let’s first look at how PHP runs. After a request PHP script is sent to the server, the server searches for the corresponding file on the disk, first compiles the script, then executes it, and finally sends the result. The time spent consists of finding files + opening files + reading files + compiling files. ZendCache is a high-speed Cache for PHP scripts. It can store the compiled results of the PHP script file just executed in the memory of the Web server. If someone requests this page again next time, it can send it out quickly. This eliminates the time it takes for the server to compile the script every time the user requests a php file. At the same time, the time spent searching and reading PHP files from the disk is eliminated. Therefore, the corresponding speed of the server can be greatly improved.
Currently ZendCache can only run on Linux (glibc 2.1), Solaris 2.6 or above, FreeBSD 3.4 and 4.0. Unfortunately, it currently does not support Windows systems.
2. Install and use ZendCache.
Register a user on zend.com, log in to zend.com as this user, and then download http://www.zend.com/store/products/zend-cache.php at the following address. Since zendCache is a software that requires membership fees, we can only download a trial version with a limited date that can be used for 30 days. However, it is a fully functional software package. Give it a try and you can experience its powerful features. To download its trial version, directly select "Test drive available" to download.
The entire download is divided into three steps. The first step is to download the ZendCache software package and directly select the software package for the corresponding platform from "Supported Platforms". Pay attention to the platform for which the software is applicable and the corresponding PHP version and class library type.
The second step is "Request Product License", which is to obtain authorization from zend.com and require the user to provide the Host ID of his machine, which is the MAC address of the computer's network card. zend.com provides a tool to read the host network card address. Users can download a small program called lmutil.Z from zend.com, decompress it and execute it to obtain the computer's network card address. Execution method:
# ./lmutil lmhostid
to obtain the host ID. In addition, users can also find the MAC address of the network card from /var/log/messages.
Fill this ID number into the license application form, select "request", and wait patiently. Zend.com will send you an email within 48 hours to notify you that you can download your own license. After receiving the email, go directly to http://www.zend.com/store/pickup.php to download. License is a file named zend_cache.dat.
Installation (this article takes installation in a Linux environment as an example)
decompresses the ZendCache-1[1].0.0-PHP_4.0.4-Linux_glibc2.1-i386.tar.gz file
# tar –zxvf ZendCache-1[1].0.0-PHP_4.0.4-Linux_glibc2.1-i386.tar.gz
# cd ZendCache-1[1].0.0-PHP_4.0.4-Linux_glibc2.1-i386
# cp *.so / usr/local/Zend/lib
Then, copy zend_cache.dat to the /usr/local/Zend directory.
Then edit the php.ini file and add the following lines:
; Start of sample Zend Cache configuration section
zend_cache.use_cwd=1
zend_cache.memory_consumption=64 ; 64MB
zend_cache.validate_timestamps=1
zend_extension=/usr/local/lib/ZendCache.so
; End of sample Zend Cache configuration section
Restart the apache server. Make the changes you just made take effect.
Edit a simple php file test.php in the htdocs directory of the web server with the following content:
<?
Phpinfo();
? >
Then, type http://localhost/test.php on your browser
if the second part appears on the screen
This program makes use of the Zend scripting language engine:
Zend Engine v1.xx, Copyright (c) 1998-2000 Zend Technologies
with Zend Cache v1.xx, Copyright (c) 1999-2000, by Zend Technologies
, indicates that ZendCache is working normally. All that's left is to look at its Cache hit effect.
3. Test the hit rate of ZendCache.
Along with the ZendCache software package, there is also a part of php code, which can visually display the hit effect of ZendCache. Simply copy the cache_gui subdirectory to the htdocs directory of the web server. Type http://localhost/cach_gui/index.html in the browser URL bar to see the Cache hit effect. As shown in the figure below, it is the hit effect diagram after the author installed zendCache:
If the graphics in the browser are not displayed and you are prompted that the GD module in the compiled PHP does not support the display of png graphics, then you have to compile PHP again to make the GD module support the display of png graphics. Articles on how to compile PHP so that it supports png can be found online, and are not described in this article. If you don't know whether your PHP supports png, you can use the phpinfo() function to check. Under normal circumstances, if it is not specifically stated to support png during compilation, GD will not support png by default during compilation.
Note: If you use ZendOptimizer at the same time, then the above lines should be placed after ZendOptimizer, otherwise your Apache server will not start.