14
Aug

PHP tutorial: Profiling performance to find bottlenecks | lynda.com


{QTtext}{timescale:100}{font:Verdana}{size:20}{backColor:0,0,0}
{textColor:65280,65280,65280}{width:960}{justify:center} {plain} [00:00:00.51]
One of Xdebug’s features is a profiler, which analyzes program execution [00:00:04.95]
to measure memory usage, duration, and frequency of function calls. [00:00:09.81]
The profiler generates files that can be analyzed with third-party tools, [00:00:14.15]
known as cache grind, which I will demonstrate. [00:00:16.46]
Similar to other techniques that I’ve demonstrated, profiling is susceptible [00:00:20.15]
to the observer effect, as it has an impact on the speed of program execution. [00:00:25.03]
Therefore, Xdebug leaves profiling off by default. [00:00:28.98]
I’m going to selectively enable the profiler. [00:00:31.13]
Meaning, instead of recording every single page,
I will need to pass an additional header [00:00:35.31]
or cookie to manually trigger it. [00:00:38.14]
This way I don’t have to sort through all the generated files [00:00:41.75]
to find the particular one I’m interested in. [00:00:43.29]
By default, Xdebug will write to/tmp/cashgrind.out.processID. [00:00:51.57]
Switching to the terminal, I’m going to edit the PHP configuration. [00:00:55.12]
sudo nano -w /etc/php5/apache2/php.ini. [00:01:04.83]
Skipping to the end of the file, I’m going to add one line that will allow [00:01:08.26]
Xdebug’s profiler to be manually triggered. [00:01:10.67]
xdebug.profiler_enable_trigger=1. [00:01:19.32]
Exit and Save then Restart the Web server, sudo /etc/init.d/apache2 restart. [00:01:28.08]
Now that Xdebug is ready to profile, I’m going to demonstrate how profiling [00:01:31.85]
can find a bottleneck. [00:01:32.88]
Go to the IDE and scroll to the bottom and add two new functions. [00:01:38.88]
The first will be to simulate slow execution of a function by counting to 100,000. [00:01:44.96]
Slow execution, so function slow for ($i=0; $i

Tags: , ,

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *