Whether you are an experienced developer or just getting started it is important to know how to measure the performance of your scripts and applications so that you can learn to make improvements and optimizations to your code. There are several tools available, both commercial and free, that will allow you to make these kinds of measurements in your environment. Some tools are very simple and only look at log times to determine how long a request has taken; others have more features and offer full application profiles, query analyzers and execution plans. This article compares two of the most popular solutions under free license that you can begin using today to profile your PHP applications.
PHP Quick Profiler
PHP Quick Profiler, or PQP, is developed by ParticleTree and is a small, light-weight tool for measuring the quality of your PHP code. It is designed to act like more like a plug-in than an actual software tool so it runs entirely in the browser. Tabs along the top of the page show the major data such as load time, database queries that have been run, memory used and how many files were accessed or included in the load. Color coded bars along the side break down the script into four categories: logs, errors, memory or speed.
One of the best things about PQP is that you do not need to do a lot of complicated setup or install to make it work. There are no extra CSS or script files needed to make PQP show up the way it should and it has a pretty stunning interface for a free product.
Setting up PHP Quick Profiler is quick and easy. For most applications you can just download the zip file, unzip it into your application and add an include statement for
PhpQuickProfiler.php into each page that you want to activate PQP. This will turn on console, memory and file logging. However, the hard part of installation comes when you want to review your database connection activity. This may not be possible based on the way you are accessing your database since PQP requires that all database interaction be abstracted. They provide a sample database class for those that would like an example but it can be tough for the beginner to get it to work properly. Nonetheless, the work is well worth it since the database component features some useful tools such as a debugger and an “explain” feature for each query. The results for each query can be viewed independently so you can identify if a query needs optimized or if indexes are not being used properly.
Overall, PHP Quick Profiler is a powerful tool for finding problems in your code or for help identifying areas that need improvement. The interface is fantastic and makes it easy to use for beginner or advanced users.
Xdebug is developed by xdebug.org and is a robust, powerful tool for PHP profiling and analysis. Xdebug may not have the slick interface of PHP Quick Profiler, but it does have many great features that are worth taking a look.
Getting started with Xdebug is easy. Downloads are provided to match the version of PHP you have installed and installation instructions are provided to get you quickly up and running. The output for each file is available via a cachegrind compatible file which will require the KCacheGrind tool or WinCacheGrind, both freely available on SourceForge. A small change to your
php.ini enables Xdebug and it will begin to write the profile information log files.
Once you have a log file and one of the applications to view it, you can begin to get the information you need about your PHP application. Tabs along the top will allow you to switch between showing the time spent on each function, how many times a specific function was called and how much time was spent in a currently selected function. There is also a Distance column that will tell you how many function calls are between the listed function and the currently selected function.
The downside to xdebug is the lack of database connectivity and analyzation tools. Xdebug appears to be a great tool for getting deep-down information about memory usage and helping with the optimization of function calls but it will not help you identify bottleneck issues created by database calls.
As you can see from these two tools, profilers can come with many different options and sets of functionality that allow you to find a tool that will fit best with your needs. Some tools have modern interfaces while others opt for more powerful reporting tools instead. If you need a free tool it can be difficult to find a PHP profiling tool that has all of the features you may want and the interface that you like all rolled into one. Identifying what kind of data you are looking for and what information you need from a profiling tool will allow you to choose the best solution for your needs.
Help us spread the word!
If you liked this article, consider enrolling in one of these related courses:
|Oct 20-21||Web Development with PHP/MySQL|
|- Classroom - Online|