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
- How does the data above changes when you run through the application multiple times
- What are the particular lines of code, function calls and class methods where most of the memory is consumed 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
- Average execution time of all PHP code in the calls made from this line (Time with children
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 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 11 in index.php script was visited 1 time, the application spent 0.005 ms executing this line, however all calls made on this line took 656 ms making it the longest Time with Children line. This of course is not surprising given that this is index.php file.
|
|
|
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 11 in index.php, with the total Time with children of 656 ms.
|
|
|
When you double click index.php entry in Location column, PhpED will open index.php in the Editor and highlite the line #11, as illustrated
|
|
|
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
|
|
|
What are the particular lines of code, function calls and class methods where most of the memory is consumed by the application
Similar to Line Profile, PHP Memory profile in PhpED lets you find the lines where PHP Applications adds or releases the largest amount of memory. Simply sort the Memory tab by clicking on the header and then double click on the top line there. PhpED will open the editor and navigate to the corresponding line of the source code.
|
|
|
How to find the longest running SQL queries in PHP code?
To profile all of the SQL queries in PHP code be sure to check SQL profiler in Profiler menu when running PHP Profiler in PhpED. Profiler results will include SQL Profiler with full information about SQL calls from PHP code , their fetch and execution time for all lines along with visual chart
|
|
|
Learn more about PHP SQL Profiler
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!
|