Debugging PHP Programs By Email

Okay, so this is pretty evil.

Ever write any Node.JS? I’m quite partial to the Express framework. Perhaps what I love most about Node/Express is that it’s so easy to debug when things go wrong. It’s just a matter of logging stuff to the console.

PHP isn’t quite so easy to debug. I’ll quote Silverdrag from StackOverflow on this one:

In PHP, you have 3 categories of debugging solutions:

  • Output to a webpage (see dBug library for a nicer view of things).
  • Write to a log file
  • In session debugging with xDebug

Learn to use those instead of trying to make PHP behave like whatever other language you are used to.

All of these solutions work, but aren’t exactly what you’d call great. Which is why I’ve started debugging PHP via e-mail. It’s exactly what it sounds like.


if (x = y){
mail('me@matthewhughes.co.uk', 'x = y', x);
} else {
mail('me@matthewhughes.co.uk', 'x != y', x);
}

Yes, I know it’s crazy. Yes, I know it’s a little bit evil. Yes, I know it’s ugly as hell. But it works!  And it’s still not as insane as implementing an SSH server in PHP.

Do you have an unorthodox way of debugging your web applications? I’d love to hear about it. Drop me a comment below, will you?

About Matthew Hughes

Matthew Hughes is a software developer, student and freelance writer from Liverpool, England. He is seldom found without a cup of strong black coffee in his hand and absolutely adores his Macbook Pro and his camera. You should follow him at @matthewhughes.

1 comment

  1. Just No.

    First off, when you’re writing your Unit Tests in PHPUnit (Or what ever test tool you choose) then printing to screen works just fine… You are writing tests for your code right? ;o)

    Then, xDebug is really powerful, yes sometimes a bit frustrating to get started with but it’s worth putting the effort in to get up to speed with it as once you are, it’s incredibly powerful.

    For sometime a bit more off the wall though, New Relic is Awesome on production servers if you can budget for it as it handles all the error logging and alerting you out of the box.

Leave a Reply