Debugging PHP With Xdebug
March 25, 2014
WHO IS THIS GUY!?
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."
I don't need xdebug...
Stop debugging manually!
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!
sudo apt-get install php5-xdebug
sudo yum install php-pecl-xdebug.x86_64
You may already have it. Check:
brew install xdebug-php
You're using Vagrant right?
Of course you are!
Chances are your vagrant box already has Xdebug.
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)
Enable Remote Debugging (Vagrant / Non-Local System)
*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
Search Chrome Store for "xdebug-helper"
Chrome has great URLs >.<
Ready to debug?!
In the process of finishing this talk...
Xdebug, PHP, Phpstorm conspired against me...
But I did get some example code working: