In my previous post I wrote about using xDebug with Laravel Homestead and Sublime Text for debugging PHP.
Today I would like to add to that topic by showing you how to use xDebug to profile your application.
Homestead comes with easy install for Blackfire which is basically a nice web GUI around xDebug. I found it very slow as my connection are spotty at times, so I thought I would just profile locally.
Enable profiling
Append the following to /etc/php5/fpm/conf.d/20-xdebug.ini
:
xdebug.profiler_enable_trigger = 1;
xdebug.profiler_output_dir = "/home/vagrant/xdebug"
The first line will allow you to use the chrome extension from last post to enable profiling when you need it. Don’t run your app with xDebug profiling on all the time, it can slow it down considerably.
The second line will output the result of the profiling to a folder you specify.
Setup a shared folder for outputs
In your Homestead.yaml add a folder entry for the folder you specified in your xdebug config.
This will allow you to view the files on your host OS.
Reading the output
The only tool I found to read the output is kcachegrind which coincidentally is pretty similar to blackfire.
It’s easy to install:
brew install qcachegrind
brew install graphviz
Read an output file:
qcachegrind filename
For help on reading the output I found this to be a good resource.