CHAPTER 14 – USING ZPS (ZEND PERFORMANCE SUITE)
ZPS is a commercial product from Zend.com. ZPS provides tools for Automatic Optimization. By using the Zend Optimizer (http:// www.zend.com/store/products/zend-optimizer.php), you can improve your performance by 20 percent without making any code changes. Compiled-code Caching. By using the Zend Performance Suite's Accel- eration module (http://www.zend.com/store/products/zend-performance- suite.php), you improve performance by 50300 percent, and sometimes even more for most applications.
Content-Caching. When using the Zend Performance Suite's Content- Caching module, you can receive an enormous performance boost--and literally reduce the execution overhead of your application to zero. Per- formance boost of 10,000 percent (100 times faster) are not uncommon with this practice. Content Compression. Although being slightly different from all the aforementioned methods, compressing your content (typically the HTML parts of it) can result in your application appearing to perform faster and be more responsive because pages will take less time to transmit over the wire.
Automatic Optimization To understand Automatic Optimization, you first should understand the execution architecture of PHP and the Zend Engine. Consider the following example: <?php $i = 5; $i++; ?> How does PHP execute it? In practice, PHP employs a two-stage execu- tion architecture. The first stage is compiling the source code into intermediate code, and the second stage is executing the intermediate code. What does inter- mediate code look like? If you are familiar with Assembly, intermediate code would look slightly familiar. It consists of relatively simple operations, which have a result and up to two operands. For instance, the intermediate code for the previous example is going to look more or less like this: 1 ASSIGN($i, 5) 2 T1 = $I 3 INC($i) First, 5 is assigned to $i, then to the value of $i before the increment is retained in T1, and finally $i is incremented. But wait--no one is using T1 isn't ; it a waste of time retaining it? The answer is yes, and this is exactly where Automatic Optimization comes into the picture. The Zend Optimizer (a part of the Zend Performance Suite, but also available for free from Zend.com) works by analyzing your application's inter- mediate code, and replacing inefficient patterns with more efficient patterns that do the same thing. In our case, it would detect that post-increment is not really necessary, and replace it with pre-increment. In other words, it would get rid of Line 2, and the resultant code would look like this: 1 ASSIGN($i, 5) 2 INC($i) Note that using the Zend Optimizer does not make any changes to your source code; the process happens in memory, and only operates on compiled, intermediate code. The biggest issue with automatic optimization is that typi- cally it cannot yield more than 20 percent performance improvement, and in many cases, even much less. For that reason, automatic optimization should typically be complemented by additional performance improvement measures, such as compiled code caching.