heliocore.com
Frank Carey
CEO - Co-founder
Debugging Drupal with Xdebug
Heliocore
heliocore.com
Frank Carey
CEO - Co-founder
Follow me @frankcarey
heliocore.com
Frank Carey
CEO - Co-founder
What is XDebug?
● PHP debugger extension available since 2002
● Created by Derick Rethans
● Written in C and Open Source
● Uses DeBuGger protocol (DBGp)
● Starts when your php process starts, and tries
to communicate with port 9000 (default)
● Provides all kinds of goodies we’ll talk about!
XDEBUG: Hey, anyone listening on ip address
127.0.0.1 and port 9000? If not, I’m just going to
continue..
IDE: Hey XDEBUG, I’m here so hold on.. I’d like
you to stop at these breakpoints if you get to them.
XDEBUG: OK, I’ll reply back if I hit one of those
breakpoints.
XDEBUG: Hey, IDE I just hit breakpoint 2 and
stopped.. What do you want me to do now? ...
How XDebug communicates
1) Check if already installed (phpinfo())
2) PECL
pecl install xdebug
(OR) HOMEBREW
brew install php56-xdebug
3) Add xdebug module and settings to php.ini*
*The php.ini you have for cli (drush) is often different than
your Apache php.ini
Installing Xdebug
You need to know the right ip address to connect to!
Are you running php local or remotely?
Running Local (127.0.0.1) Running remote (192.168.X.1)
XAMP/WAMP etc
Acquia Dev Desktop
OSX native php
Homebrew php
DrupalVM
Vagrant
VirtualBox
Docker
Remote Server
Check phpinfo() or php -i | grep xdebug
zend_extension=/.../xdebug.so
xdebug.remote_enable=On
xdebug.remote_host=192.168.99.1
xdebug.remote_autostart=1
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"
xdebug.max_nesting_level=256
Php.ini Xdebug settings
heliocore.com
Frank Carey
CEO - Co-founder
Debugging
without Xdebug
Debugging Without XDebug
● var_dump(), print_r(), echo()
● drupal_set_message()
● Devel Module:
○ dpm/dsm()
○ drupal_debug()
Example dpm() output using Devel module.
● Shooting in the dark / trial and error
● Pollutes screen
● Memory intensive
● Requires altering your code (and remembering
to clean it up)
● dpm() not reliable
● Very limited functionality
○ Can’t pause execution
○ Read only
○ One thread only
Limitations of the Devel approach
● Requires an IDE (that has good support)
● Requires a PHP extension to be installed
● Requires ini settings
● Adds overhead to PHP when installed:
○ Drupal
○ Composer
Limitations of Debugging with XDebug
heliocore.com
Frank Carey
CEO - Co-founder
Debugging
WITH Xdebug
● Real-time debugging
○ Stepping through code
○ Inspecting variables
○ Call Stack
● Advanced Breakpoints
● Watches
● Changing Values on the fly!
Features we’ll Demonstrate
heliocore.com
Frank Carey
CEO - Co-founder
Setting up
PHPStorm
(DEMO)
heliocore.com
Frank Carey
CEO - Co-founder
Watches
(DEMO)
heliocore.com
Frank Carey
CEO - Co-founder
Debugging
Basics
(DEMO)
heliocore.com
Frank Carey
CEO - Co-founder
Advanced
Breakpoints
(DEMO)
THANKS!
Follow me @frankcarey
Check out Ahoy 2.x at: bit.ly/ahoycli

Debugging Drupal with Xdebug

  • 1.
    heliocore.com Frank Carey CEO -Co-founder Debugging Drupal with Xdebug Heliocore heliocore.com Frank Carey CEO - Co-founder Follow me @frankcarey
  • 2.
  • 3.
    What is XDebug? ●PHP debugger extension available since 2002 ● Created by Derick Rethans ● Written in C and Open Source ● Uses DeBuGger protocol (DBGp) ● Starts when your php process starts, and tries to communicate with port 9000 (default) ● Provides all kinds of goodies we’ll talk about!
  • 4.
    XDEBUG: Hey, anyonelistening on ip address 127.0.0.1 and port 9000? If not, I’m just going to continue.. IDE: Hey XDEBUG, I’m here so hold on.. I’d like you to stop at these breakpoints if you get to them. XDEBUG: OK, I’ll reply back if I hit one of those breakpoints. XDEBUG: Hey, IDE I just hit breakpoint 2 and stopped.. What do you want me to do now? ... How XDebug communicates
  • 5.
    1) Check ifalready installed (phpinfo()) 2) PECL pecl install xdebug (OR) HOMEBREW brew install php56-xdebug 3) Add xdebug module and settings to php.ini* *The php.ini you have for cli (drush) is often different than your Apache php.ini Installing Xdebug
  • 6.
    You need toknow the right ip address to connect to! Are you running php local or remotely? Running Local (127.0.0.1) Running remote (192.168.X.1) XAMP/WAMP etc Acquia Dev Desktop OSX native php Homebrew php DrupalVM Vagrant VirtualBox Docker Remote Server
  • 7.
    Check phpinfo() orphp -i | grep xdebug zend_extension=/.../xdebug.so xdebug.remote_enable=On xdebug.remote_host=192.168.99.1 xdebug.remote_autostart=1 xdebug.remote_port=9000 xdebug.idekey="netbeans-xdebug" xdebug.max_nesting_level=256 Php.ini Xdebug settings
  • 8.
    heliocore.com Frank Carey CEO -Co-founder Debugging without Xdebug
  • 9.
    Debugging Without XDebug ●var_dump(), print_r(), echo() ● drupal_set_message() ● Devel Module: ○ dpm/dsm() ○ drupal_debug()
  • 10.
    Example dpm() outputusing Devel module.
  • 11.
    ● Shooting inthe dark / trial and error ● Pollutes screen ● Memory intensive ● Requires altering your code (and remembering to clean it up) ● dpm() not reliable ● Very limited functionality ○ Can’t pause execution ○ Read only ○ One thread only Limitations of the Devel approach
  • 12.
    ● Requires anIDE (that has good support) ● Requires a PHP extension to be installed ● Requires ini settings ● Adds overhead to PHP when installed: ○ Drupal ○ Composer Limitations of Debugging with XDebug
  • 13.
    heliocore.com Frank Carey CEO -Co-founder Debugging WITH Xdebug
  • 14.
    ● Real-time debugging ○Stepping through code ○ Inspecting variables ○ Call Stack ● Advanced Breakpoints ● Watches ● Changing Values on the fly! Features we’ll Demonstrate
  • 15.
    heliocore.com Frank Carey CEO -Co-founder Setting up PHPStorm (DEMO)
  • 16.
    heliocore.com Frank Carey CEO -Co-founder Watches (DEMO)
  • 17.
    heliocore.com Frank Carey CEO -Co-founder Debugging Basics (DEMO)
  • 18.
    heliocore.com Frank Carey CEO -Co-founder Advanced Breakpoints (DEMO)
  • 19.
    THANKS! Follow me @frankcarey Checkout Ahoy 2.x at: bit.ly/ahoycli