Ever seen this in your production php_error.log?
[16-Dec-2013 10:50:44 America/Denver] Hello there
[16-Dec-2013 10:50:44 America/Denver] ...starting loop
[16-Dec-2013 10:50:44 America/Denver] stepping through 0
[16-Dec-2013 10:50:44 America/Denver] stepping through 1
[16-Dec-2013 10:50:44 America/Denver] stepping through 2
[16-Dec-2013 10:50:44 America/Denver] stepping through 3
[16-Dec-2013 10:50:44 America/Denver] stepping through 4
[16-Dec-2013 10:50:44 America/Denver] stepping through 5
[16-Dec-2013 10:50:44 America/Denver] ...done
[16-Dec-2013 10:50:44 America/Denver] How in the world did we get here?
There’s one thing you can tell about the developer who wrote it – they don’t have a debugger up and running. Or maybe they do, it’s just too big of a hassle to fire it up and get it attached. And I am plenty guilty of this myself, having written my share of debugatory error_log statements over the years. Sometimes it’s just easier to add a trace, refresh, and tail the error_log.
Debuggers, at least those available for macs, are finicky beasts. They’re often difficult to setup, they’re a bit too assertive when you’re not actively debugging, and they don’t always work reliably. Compared with a debugger, error_log() is always there for you, seldom complains, and rarely sticks it’s nose in where it doesn’t belong. Why can’t a debugger be this way? I need to admit that nothing about what I’m going to say is ground breaking. There isn’t a new debugger out there that works better than anything before. There isn’t anything new in Mavericks that makes debugging easier. It’s just the fact that after 5 years of typing error_log("Here I am") over and over as my debugging solution, I’ve finally found a debugging setup that works without a lot of fuss. And that seems to be the key for me…in order to use it, it needs to come without a lot of fuss.
First, let’s talk about the elephant in the room…
Eclipse Is The Conversion Van of IDEs
Eclipse has every feature that I could ever hope to have. It has code syntax highlighting, code folding, code completion, jumping to definitions, SCM integration, automatic updating, debugging support, …(truncated for length). Each version has a really neat name, and that purple orb isn’t bad either. So what’s the trouble? I’m guessing anyone who’s used it probably knows…it’s just too sluggish. It probably doesn’t slow me down that much in actuality, but the perception is that I’m moving at a crawl. Even the slightest lag in responsiveness, multiplied thousands of times per day, per month, per year…it adds up. It feels like I’m driving a old conversion van. It’s great for loading the kids up, driving for 7-8 hours at a time without stopping because there’s a port-a-potty in the back, a combo TV/VCR in the front, and a refrigerator with cold beverages and salami in the armrest. But when you step on the gas, not much happens. I want my IDE to perform like a sports car. I want it to throw me back in my seat when I step on the gas, even if I’m already going 90. I shouldn’t have to wait on it, it should have to wait on me.
So, after years of trying my best to get used to Eclipse, I finally gave up on it completely. Sure, I still have it installed on my machine, but I did remove it from my dock. And sure, I can still launch it with Alfred. But when I do, I’m reminded of why I stopped doing so after the first 10 seconds of staring at the splash screen. But what about debugging? How would I ever go back to the old error_log("LOOK HERE!") again? Luckily, I didn’t have to.
In case some of you are in the same boat, I offer my no-mess, no-fuss PHP debugging setup on a mac. It’s not fancy, but it works. I can turn it on with a click, and turn it off just as easily. And just so you know, there are lots of tutorials on how to install and setup these components elsewhere. So I’m not going to include setup instructions. This is simply a list of the components that comprise my PHP development setup with debugging support.
Sublime Text 2
Sublime Text 2 is a great text editor, allowing tons of plugins. It’s quick, looks great, and provides quick access to just about everything I need. The key plugins that I use are
PackageControl – https://sublime.wbond.net/
SublimeLinter – https://github.com/SublimeLinter/SublimeLinter
SublimeCodeIntel – https://github.com/SublimeCodeIntel/SublimeCodeIntel
GitGutter – https://github.com/jisaacks/GitGutter
These provide most of the advanced PHP editing features that I need. Best of all, they do it quicky.
Yep, the very XDebug that we’ve known and loved for years. There’s nothing new about this one. I did tweak a few of the configuration options in my php.ini file. Here’s what it looks like
This is a standalone app that serves as the debugging interface. You can open code files, add breakpoints, and step through code as needed. It may not be the prettiest app, but it works quite well.
Chrome extension for enabling debugging. This shows up as a fun little bug in my address bar, and allows me to debug, trace, profile, or disable with the click of a mouse. I can turn on debug mode, and magically attaches in MacGDBp. I can break on the first line of execution, or set a breakpoint and break there. It also allows some preferences where I can set which domains the little bug shows up on. I’ve set this to localhost and my qa servers since I won’t need to debug google.com. And once I’m done debugging, I can simply disable debug mode again and go on my way. No fuss, no mess.