var_dump($foo);
print_r($bar);
die($baz);
Are these your current debugging tools? Wouldn't it be nice to see $foo, $bar, and $baz while the code is still being executed? Watch it change, live? And not have it just dumped all over the output of your otherwise beautiful app? We'll install XDebug, set up your IDE to use it (with examples shown for PhpStorm, Netbeans, and ZendStudio), then we'll actually walk through some badly written code that needs to be debugged.
3. What I hope to impart:
1)What Xdebug is.
2)How to install Xdebug.
3)How to set up your IDE to use Xdebug.
4)How to set break points.
5)How to step through your code and see what's going on.
6)How to skip over the boring parts.
5. What is Xdebug?
Xdebug is a tool to make your developing life easier.
It is a PHP extension that you can just pop into place and start using.
●“Xdebug - Debugger and Profiler Tool for PHP” (Xdebug.org, site title)
●“Xdebug: A powerful debugger for PHP.” (Xdebug.org, site decription)
●“Xdebug is a PHP extension which provides debugging and profiling capabilities.” (Wikipedia, with its own source.)
●Open Source. Made with dedication by Derick Rethans (and some helpers)
●Available on GitHub
7. PECL:
# pecl install xdebug
Homebrew (on a Mac)
# brew install <php version>-xdebug
Apt/Yum/etc
These methods will vary from distro to distro and repo to repo.
Build from source.
This is beyond the scope of this talk, check Xdebug.org for
details.
Maybe it's already installed!
Fire up a phpinfo() to check.
8. Configure PHP to Use Xdebug
add the following line to php.ini (or in a separate file, if you
have your INI set to read a a sub-directory or such.)
[xdebug]
zend_extension="/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable = 1
Restart your webserver.
Load up a 'phpinfo()' page. You should see the fact it is
loaded and some details.
9. Taken From: http://wiki.netbeans.org/HowToConfigureXDebug
● Xdebug is incompatible with the Zend Optimizer and Zend Studio Debugger
extensions. These extensions should be commented out.
● From PHP 5.3 onwards, you need to use zend_extension and not zend_extension_ts.
● Get xdebug's debugclient working on localhost first, then add Netbeans.
● Use the bundled command line client "debugclient" on localhost, debugging simple php code
(e.g. a phpinfo file), with any firewalls and other competing factors or config disabled or removed.
When you've got this running, then your fight with Netbeans will be on solid ground, and will
probably be surprisingly easy.
● Instructions on installing Debugclient are cunningly hidden right at the bottom of
http://www.xdebug.org/docs/install
● If you are mapping server paths to project paths, you must map the full project folders to each
other, not the parent folders.
● More Info on Debugging in Netbeans here: https://netbeans.org/kb/docs/php/debugging.html
17. Getting Xdebug to react!
●Using a Browser Extension
(Ideas from JetBrains wiki. More there.)
–Chrome: Xdebug helper
–Firefox: easy Xdebug
●Using Bookmarklets
–https://www.jetbrains.com/phpstorm/marklets/
–http://tool.ihacklog.com/xdebug-bookmarklet/
●Using a cookie
–(This is basically all both of the above utilities are doing.)
–Name: XDEBUG_SESSION
–Value: (varies by IDE)
27. So Long and Thanks for all the Fish!
Many thanks to MadisonPHP for hosting this amazing conference and bringing me here to speak. Thanks
also to the wonderful sponsors.
And a HUGE thank you to you for putting up with my rambling and raving.
Twitter: @sprunka
Email: sprunka@gmail.com
Joind.in: https://joind.in/talk/177b7
“Baby Steps”?
”Giant Leaps”?
What is this, the Lunar Lander? Parcour?
Nope... No rocket science here. No death defying high rise obstacle courses either.
6 kids. From 17 down to 4.
I played with PHP first in 1998-99. kept “playing” with it for 12 yrs. Then ZendCon. In all, that&apos;s more than 15 yrs of PHP experience. ZCE PHP 5.3 Senior Developer @ PO2Go
Over 35 yrs of acting experience, including school and community. Active with several local community theatres currently, including being a founding member on the board of a new one.
Pansexual, Genderfluid/GenderQueer. Cville Pride, Shenandoah Valley Pride.
Sooooo.... What is Xdebug?
Xdebug is a Step debugger.
The how of it all is magic to me. –
Your IDE listens for a cookie and your browser sends a cookie and magically you are stepping through your *local* code that is the same as the code existing in your VM, or on your server.
Development, Staging, or Production. You can run with Xdebug anywhere.
I&apos;m sure there are plenty of caveats to that, but it pretty much “just works”
The hard way: build from scratch.
The easier ways:
PECL/PEAR
Mac Homebrew
The easiest:
It&apos;s already installed/baked into your PHP installation.
(don&apos;t forget to change the path and filename to the correct one — but make sure you use the full path)
I don&apos;t use Netbeans anymore, and all the configuration related to Xdebug that I could find deal more with the configuration of Xdebug itself, not necessarily in conjunction with Netbeans.
So, I just ended up grabbing a screenshot from the web.
It&apos;s been even longer since I used Zend Studio, and they tend to prefer you using Zend Debugger, so I just grabbed another screen shot from the web.
PhpStorm is my current go-to IDE
Triggering Xdebug requires a cookie. That&apos;s it.
I use a handy Extension in Chrome called Xdebug helper.
There are also handy extensions for Firefox, Safari, and Opera. Not sure about IE….who uses IE for dev anyway???
If you either don&apos;t want to or are unable to install an extension, that&apos;s fine, you can add a bookmarklet, or just add a cookie and add XDEBUG_SESSION_START to the path.
Since Xdebug is a STEP debugger, let&apos;s get stepping, shall we??