xdebug 101

Debugging PHP With Xdebug


MemphisPHP.org 

March 25, 2014

WHO IS THIS GUY!?

JOE FERGUSON

Professionally

  • Web Developer at RocketFuel

  • PHP / LAMP Focused


Semi Professional

  • Co-Organizer for MemphisPHP.org

  • MidsouthMakers - Hackerspace Leader

  • HACKmemphis.com Organizer

What is Xdebug?


Xdebug is a PHP extension that provides debugging and profiling capabilities to PHP.

Xdebug uses the DBGp debugging protocol.

What is a debug?

"Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge in another." 
- http://en.wikipedia.org/wiki/Debugging

I don't need xdebug...



You're Wrong!

Stop debugging manually!

Why Xdebug?


Pause your application during processing
Watch variables change values
Easy to find information about
Widespread IDE Support

Why not zend Debugger?


If you are already in the Zend world, stick with it!


Getting Started

Linux:
sudo apt-get install php5-xdebug
sudo yum install php-pecl-xdebug.x86_64
Mac:
You may already have it. Check: 
/usr/lib/php/extensions/no-debug-non-zts-2010052/xdebug.so
If not
brew install xdebug-php
Windows:
http://xdebug.org/download.php

WAIT!


You're using Vagrant right?

Of course you are!

Chances are your vagrant box already has Xdebug.

Caution!

Remote Debugging*

If you ARE using vagrant, ensure you're port forwarding 9000 to the vagrant box.


*You probably don't want Xdebug on your production environment. This is better off in a staging environment

Configure php to use Xdebug

Add this line to php.ini: (consult your OS Docs for specifics)
zend_extension=/usr/lib/php5/20121212/xdebug.so 

Enable Remote Debugging (Vagrant / Non-Local System)
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.show_local_vars=0
xdebug.var_display_max_data=10000
xdebug.var_display_max_depth=20
xdebug.show_exception_trace=0 

*Note: You can use Xdebug OR Zend, not both. Make sure to disable Zend Debugger if you want to use Xdebug

Check your work so far

If you don't see "with Xdebug..." Something isn't right

Create bookmarklets

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

OR

Chrome App:
Search Chrome Store for "xdebug-helper"

https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc

Chrome has great URLs >.<

Configure your IDE


Ready to debug?!


In the process of finishing this talk...


Xdebug, PHP, Phpstorm conspired against me...

But I did get some example code working:

https://github.com/svpernova09/Xdebug101-Examples 

Links

http://xdebug.org

http://www.jetbrains.com/phpstorm

xdebug 101

By Joe Ferguson

Navigation instructions

Press the space key or click the arrows to the right