Top Banner
Debugging and Profiling PHP Applications Logan Lindquist @llbbl
23

Debugging and Profiling PHP Applications

May 18, 2015

Download

Technology

Logan Lindquist

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Debugging and Profiling PHP Applications

Debugging and Profiling PHP ApplicationsLogan Lindquist @llbbl

Page 2: Debugging and Profiling PHP Applications

Debugging vs Profiling

Debugging

Bug fixing

Used during Development to minimize bugs

Profiling

Performance tuning

Page 3: Debugging and Profiling PHP Applications

?????

Page 4: Debugging and Profiling PHP Applications

What Is This Magic?!?

Page 5: Debugging and Profiling PHP Applications

Xdebug is AWESOME

Pretty var_dumps

EnhancedStack Trace

Debugging

Profiling

Page 6: Debugging and Profiling PHP Applications

OMGWTFBBQ Install it NOWOSX:

Install homebrew

Follow instructions: https://github.com/Homebrew/homebrew-php#installation

brew install php54-xdebug

Ubuntu:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-xdebug

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Windows: Install Vagrant then follow Ubuntu

Page 7: Debugging and Profiling PHP Applications

Configure Xdebug for DebuggingTurn 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"

Page 8: Debugging and Profiling PHP Applications

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

Page 9: Debugging and Profiling PHP Applications

Make sure you have the right PHPSettings > PHP > Intrepreters

....you should see xdebug

Page 10: Debugging and Profiling PHP Applications

Here is how to check symlinked or not

Tools > Deployment > Configuration

Page 11: Debugging and Profiling PHP Applications

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

Page 12: Debugging and Profiling PHP Applications

How to trigger a debug session

• Javascript bookmarklets

• Chrome extension

• Within PhpStorm

• Magic

• Production crashes Let's cover the first three shall we?

Page 13: Debugging and Profiling PHP Applications

Jetbrains Has The Goodies

http://www.jetbrains.com/phpstorm/marklets/

• Start Debugger:

• Goto page

• Hit Start Debugger

• Hit Stop Debugger when done debugging

• Debug this page:

• Goto page

• Hit Debug this page

Page 14: Debugging and Profiling PHP Applications

Chrome ExtensionName: Xdebug Helper

https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en

Page 15: Debugging and Profiling PHP Applications

PhpStorm

Page 16: Debugging and Profiling PHP Applications

PhpStorm + Xdebug

Page 17: Debugging and Profiling PHP Applications

Profiling with PhpStormTools > Analyze Xdebug Profiler Snapshot

Page 18: Debugging and Profiling PHP Applications

MCG https://itunes.apple.com/us/app/mcg/id799178412?mt=12

Page 19: Debugging and Profiling PHP Applications

Profiling with MCG

Page 20: Debugging and Profiling PHP Applications

XHProf

Page 21: Debugging and Profiling PHP Applications

XHProf

Page 22: Debugging and Profiling PHP Applications

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

Page 23: Debugging and Profiling PHP Applications

In Review...

• Installed Xdebug

• Setup Xdebug with PhpStorm

• Configured Xdebug for profiling or debugging