Section 14.4. Profiling with Zend Studio s Profiler


14.4. Profiling with Zend Studio's Profiler

One method of optimization is manually finding bottlenecks in your application and tuning the relevant code. The biggest downside to this method is that there's no "magical" way of doing it. You simply need to audit your application and think of ways to change it so that it still does the same thingonly faster. Generally, you should only optimize those sections of your application that account for most of the overhead. Why is this so important? First, spending time optimizing a section that accounts for a fragment of the overhead is a poor investment of your time because it is unlikely to affect the overall application performance. Worse, as optimization often involves writing less-beautiful code that performs faster, optimizing the wrong sections can result in reduced code readability. Without the benefits of improved performance, this is simply a bad idea.

Luckily, today you're not left completely on your own. You can get a serious head start by profiling your application using the Zend Studio (http://www.zend.com/store/products/zend-studio.php). Profiling your application gives you important information, including which parts of your application are taking the most time, what your application's call trace looks like, how many times each function is being called, and so on.

Profiling is an essential tool in improving the performance of PHP applications. Profiling summarizes the data that makes up the PHP application and represents it in the form of a graph. The graph sets out the important features of the application. By placing timers within the code and running them over and over, the profiling tool is able to build a "profile" of how fast or slow specific areas of the application will run.

Zend Studio Client provides a powerful profiling tool. It is designed to help discover bottlenecks and other areas that need to be optimized to improve the program's performance. An extensive library of profiling benchmarks is included with the Client product.

Before optimizing your application, you should always profile it (see Figure 14.5). Determine where the bottlenecks are, and concentrate in those sections that account for most of the overhead. Profile again after every optimization you make; you may find out that what you thought was faster is in fact slower, or that what you thought would only be 10 percent faster is actually 50 percent faster. Finally, don't optimize snippets that account only for tiny fragments of the overhead; this only reduces readability without yielding any noticeable performance gain.

Figure 14.5. Profiling results in the Zend Studio.


For example, in Figure 14.6, you can see the profiling results of PostNuke's front page using the Zend Studio. It's clear that optimizing pnAPI.php, which accounts for more than 53 percent of the overhead, stands the best chances of actually improving overall performance. Between the first four files, almost 90 percent of the overhead is shared; even looking at any other files is likely to be sheer waste of time.

Figure 14.6. Call trace from the Zend Studio profiler.


For further information on how to use the Zend Studio's profiling capabilities, refer to the Profiling section in the Zend Studio Online Help, which is accessible via the Help menu by choosing Help Topics.



    PHP 5 Power Programming
    PHP 5 Power Programming
    ISBN: 013147149X
    EAN: 2147483647
    Year: 2003
    Pages: 240

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net