Until recently, whenever I wanted to do a load of PHP debugging, I’d pass E_ALL into the error_reporting() function to control the amount of error messages dumped to screen. As a way to become immediately aware of problems with your code, this can’t really be beat - the information is right there in your face - but as a way to track an error “in the wild”, it sucks.

So, it was nice to find out about PHP’s set_error_handler() function. This lets you completely over-ride PHP’s standard error reporting functionality and replace it with your own. What I like to do now is write an error handler which will dump to both screen and to a database whilst I’m developing the application. Then, once the application has gone live, I’ll turn off the screen dumping - leaving the application logging to the database for a couple of weeks. Then, when I’m pretty damn sure that nothing’s going awry I’ll reduce the amount of logging to only show actual errors, rather than including purely informative information.

It’s made life a lot easier for kinking out those hard to find bugs without people having to see a whole host of debugging messages that are only of any use to me, which has got to be a good thing.

permalink | View blog reactions


TrackBack URL for this entry:

other relevant pages

about wwm is a resource for web developers created by Neil Crosby, a web developer who lives and works in London, England. More about the site.

Neil Crosby now blogs at The Code Train and also runs, The Ten Word Review and Everything is Rubbish.