Ask any experience PHP developer about the devil of software programming - chances are the answer will be performance. Very often the performance of the application takes a back seat during the development but once deployed to the customer, performance - or more accurately the lack of one becomes the biggest issue. While your PHP application runs with the speed of light when there are just 3 records in the database and on the local network, in the production environment of the end user, your PHP scripts are slow, very, very slo-o-o-w. And if you ask any experience PHP developer what is the hardest thing to fix the answer of course will be the same - it is performance. How to learn which line of your PHP code is the most consuming? How to learn which part of PHP code is visited the most? NuSphere PhpED PHP Profiler has the answers and you can learn about them in this little tutorial.
For information about supported platforms and how to install PHP Debugger and Profiler modules please check debugging PHP on various platforms page.
How to tune up performance of PHP Application
The first step in tuning of the PHP Application's performance is finding the bottleneck.
You want to learn:
- Which PHP scripts take the longest time to run
- What are the particular lines of code, function calls and class methods where most of the time is spent by the application
- What are the lines of code, function calls and class methods which are visited the most - in other words get the biggest number of hits
- How does the data above changes when you run through the application multiple times
|
 |
|
How to use PhpED's PHP Profiler
If you have a PHP script open in PhpED, you can start PhpED's PHP Profiler for this script by pressing Run Profiler button from PhpED's PHP debugger tool bar or by pressing ALT-F9 on the keyboard.
Run Profiler toolbar button also provides a drop down with the list of PHP scripts previously ran with the profiler.
|
 |
|
|
When PhpED's PHP Profiler runs it collects the data from the execution of the script and presents it in Profiler Window.
It presents all the information in easy to read, graphical form and puts it right at your finger tips.
|
 |
|
Which PHP scripts take the longest time to run
PhpEd PHP Profiler tells you which scripts were the most time consuming. The columns in the PHP Profiler output table show:
- Number of Hits for each line of code in PHP script
- Average execution time of each line of code in PHP script
- Total execution time of each line of code in PHP script
- Minimum time spent in each line of code in PHP script
- Maximum time spent in each line of code in PHP script
In addition to these columns, there is a Chart column, which contains the graphic presentation of relative execution time of every line of code. The most time consuming line is set at 100% and the rest of the times are shown as the fractions of the longest interval. The Upper horizontal bar represents the total time and the lower bar represents the time spent on each line when it is executed.
|
The entries in each column can be sorted, giving you an easy way to see the performance profile of your application from any perspective. For example, you can see in the illustration below that the line number 54 in index.php script was visited 3 times, the application spent 1.4276 ms on average executing this line, the total time of the execution was 4.282 ms, minimum time spent was 1.273ms and maximum time was 1.664 ms
|
 |
|
What are the particular lines of code, function calls and class methods where most of the time is spent by the application
|
PhpED's PHP Profiler will let you jump to the location in PHP code directly from the output table. Simply double click on the entry in Location column or select Show Source item from the popup menu and PhpED will display the corresponding line of code in the editor. For example, in the illustration below you can see the line of code, which took the longest time to execute according to the Profiler output. It is line number 28 in index.php, with the total execution time of 7.977 ms.
|
 |
|
|
When you double click index.php entry in Location column, PhpED will open index.php in the Editor and highlite the line #28, as illustrated below
|
 |
|
What are the lines of code, function calls and class methods which are visited the most - in other words get the biggest number of hits
PhpED's PHP Profiler displays the number of time each line of PHP code was visited during the execution. As with any other column in PHP Profiler output window, you can sort the entries in Hit column in ascending or descending order. For example, you can sort the entries in Hit column to see which line of code was hit the highest number of times.
See how to display hits corresponding to each function and methods in PHP Profiler here
|
 |
|
How does the data above changes when you run through the application multiple times
|
The PhpED PHP debugger will let you see the results produced by the Profiler in the previous runs of the application. You can navigate to different snapshots of PHP Profiler runs using left and right arrow buttons on Profiler's tool bar.
|
 |
|
|
The buttons also display the dropdown with previously generated results and their timestamps
|
 |
|
In this tutorial you learned about the many features of the PHP Profiler and how to use them to quickly find and eliminate the bottlenecks in your PHP scripts. It is worth mentioning that PHP Profiler becomes especially powerful when used in conjunction with PhpED's PHP debugger. Additional technical information is available on the NuSphere Forum. Download a free trial of our PHP Profiler today!
|