Monday, December 12, 2016

xdebug with phpstorm and puphpet vagrant box

Xdebug is useful in many ways. debugging,  profiling, error reporting.

I have linked to many of these articles throughout this post.

Assuming you have already used that article to setup puphpet with phpstorm, this is how you can add profiling... (could add these configs to your puphpet box also!)

Configure your php.ini for xdebug with remote handling and profiling.

 /etc/php.d/99-xdebug.ini

 [XDEBUG]
 xdebug.default_enable=1
 xdebug.remote_connect_back=1
 xdebug.remote_enable=1
 xdebug.remote_handler=dbgp
 xdebug.remote_port=9000
 xdebug.remote_autostart=1
 ;xdebug.profiler_enable=1 ; uncomment for always enabled
 xdebug.profiler_output_dir=/var/www/vhosts/xdebug ; where to store output
 xdebug.profiler_enable_trigger=1 ; allow cookie/get/post to enable.
 ;XDEBUG_PROFILE cookie or GET/POST == 1

Add XDEBUG_PROFILE to your cookies or GET/POST

http://mytest.net/?XDEBUG_PROFILE=1
OR
https://www.jetbrains.com/phpstorm/marklets/ -- add bookmarks to your browser to make it easier!

Find your output

in xdebug.profiler_output_dir (directory)
file names are like "cachegrind.out.%d" where %d is unique per logged profile

Open with Phpstorm


Then select your file...


and you will end up with a profile that allows deep analysis of your script execution



Older article which may provide some more insight.

For LARGE cachegrind files... use qcachegrind