13. • PHP extension that provides debugging and profiling
capabilities
• Developed by Derick Rethans
• First released in May 2002
• Uses the DBGp debugging protocol
What is Xdebug?
14. • Debugging support
• Stack trace view
• Profiling
• Code coverage analysis
• Function logging
Features
15. • Step through code operations line-by-line
• View application data in memory at pre-determined
breakpoints
• Access function call stack
• Update variable values during runtime
• More detailed error messaging
Benefits
16. • Xdebug support exists in over a dozen IDES, including:
• PhpStorm
• Eclipse
• NetBeans
• Plain text editors too (with extensions)!
• VIM
• Sublime Text
• Notepad++
Editor Support
19. • Pre-installed w/ some environments (MAMP, XAMPP, Vagrant)
• Install from source
• PEAR/PECL
• Detailed instructions at http://xdebug.org/docs/install
Installation
20. • Locate php.ini file for your PHP installation
• Unsure? Check ‘Loaded Configuration File’ using phpinfo()
• Basic settings needed to enable remote debugging:
• zend_extension=“/path/to/your/xdebug/extension”
• xdebug.remote_enable=1
• xdebug.remote_host=localhost
• xdebug.remote_port=9000
• xdebug.remote_autostart=1
Configuration
21. • Used primarily in virtual environments such as Vagrant
• Helps the server layer find the location of local files
• PhpStorm (and presumably other IDEs) include wizards for
setting this up
Path Mappings
23. • Add query parameters to the script you’re trying to load:
• Start: [url]?XDEBUG_SESSION_START=[session_name]
• Stop: [url]?XDEBUG_SESSION_STOP=[session_name]
Enabling/Disabling Xdebug
24. • PhpStorm’s website has a list of recommended browser extensions:
https://confluence.jetbrains.com/display/PhpStorm/Browser+Debugging
+Extensions
• Chrome:
• Xdebug Helper
• Xdebug Enabler
• Firefox:
• easy Xdebug
• The Easiest Xdebug
• Safari:
• Xdebug Toogler
Browser Extensions
25. • var_dump() - stylized!
• xdebug_break() - pauses the app as if a breakpoint was set
• xdebug_get_declared_vars() - returns array of elements
defined in the current scope.
• Complete list: http://xdebug.org/docs/all_functions
Useful functions
28. • Xdebug website: http://xdebug.org
• Xdebug and You: Why You Should Be Using a Real Debugger
(Juan Treminio) https://jtreminio.com/2012/07/xdebug-and-
you-why-you-should-be-using-a-real-debugger/
• Debugging and Profiling PHP with Xdebug (Shameer C)
http://www.sitepoint.com/debugging-and-profiling-php-
with-xdebug/
Additional Resources