Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Debugging and Profiling PHP Applications


Published on

Debugging and profiling with xdebug. Learn how to setup xdebug on Ubuntu and OSX. We will also be covering how to get it working with our favorite editor, PHPStorm. A couple different profiling tools will be demonstrated.

Published in: Technology
  • Be the first to comment

Debugging and Profiling PHP Applications

  1. 1. Debugging and Profiling PHP Applications Logan Lindquist @llbbl
  2. 2. Debugging vs Profiling Debugging Bug fixing Used during Development to minimize bugs Profiling Performance tuning
  3. 3. ?????
  4. 4. What Is This Magic?!?
  5. 5. Xdebug is AWESOME Pretty var_dumps Enhanced
 Stack Trace Debugging Profiling
  6. 6. OMGWTFBBQ Install it NOW OSX: Install homebrew Follow instructions: php#installation brew install php54-xdebug Ubuntu: sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-xdebug ruby -e "$(curl -fsSL" Windows: Install Vagrant then follow Ubuntu
  7. 7. Configure Xdebug for Debugging Turn on remote debugging: xdebug.remote_enable=1 Configure what port, host, log file ... and more xdebug.remote_port= 9000 xdebug.remote_log="/var/www/xdebug.log" xdebug.remote_host="localhost"
  8. 8. Xdebug Profiling xdebug.profiler_enable = 1 xdebug.profiler_enable_trigger = 1 xdebug.profiler_output_dir = "/var/www/xdebug" xdebug.profiler_output_name = xdebug.out.%t
  9. 9. Make sure you have the right PHP Settings > PHP > Intrepreters should see xdebug
  10. 10. Here is how to check symlinked or not Tools > Deployment > Configuration
  11. 11. Gotchas • Make sure profile directory exists and is writeable by the web server • Nothing works without xdebug.remote_enable=1 • Make sure port number matches in your ini and phpstorm. Both default 9000 • SOOOOO many steps ... No shutup, stop being lazy and just do it
  12. 12. How to trigger a debug session • Javascript bookmarklets • Chrome extension • Within PhpStorm • Magic • Production crashes Let's cover the first three shall we?
  13. 13. Jetbrains Has The Goodies • Start Debugger: • Goto page • Hit Start Debugger • Hit Stop Debugger when done debugging • Debug this page: • Goto page • Hit Debug this page
  14. 14. Chrome Extension Name: Xdebug Helper helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en
  15. 15. PhpStorm
  16. 16. PhpStorm + Xdebug
  17. 17. Profiling with PhpStorm Tools > Analyze Xdebug Profiler Snapshot
  18. 18. MCG
  19. 19. Profiling with MCG
  20. 20. XHProf
  21. 21. XHProf
  22. 22. XHProf • Built by Facebook opensourced in 2009 • Xdebug not required • Way more complicated to setup • Documentation isn't great • Requires you to add xhprof methods to your code • Requires you to configure apache vhost for reporting • Has callgraph charts (directed graphs) and a couple other nice features Install isn't too bad with homebrew or apt-get
  23. 23. In Review... • Installed Xdebug • Setup Xdebug with PhpStorm • Configured Xdebug for profiling or debugging