Archive for June, 2010

Error and exception handling in PHP

Wednesday, June 23rd, 2010

For as long as I’ve been developing PHP, I’ve always cared about code quality and wanted robust error handling, to fix root cause issues. Back in 2001, I wrote a class for PHPOF called XError, which did a pretty decent job of handling errors gracefully and reporting (via e-mail or rate-limited log) a backtrace with (usually) enough information to fix the problem.

With the advent of PHP 5 and proper exceptions (at last!), I cleaned up and substantially re-wrote that class to form a new one, which has actually been on my PEAR channel for several years and is in use across many live systems at work, but which I’ve never written up. It’s called Exception_DefaultHandler and is, well, a great class to throw in any project to use as a default error/exception handler. It’s lightweight, should work anywhere really, and is a major help with root cause analysis. It’s often still helpful to use higher level exception handling in your application, but even then you might want to pass the exception down to Exception_DefaultHandler::handleExceptionManual() to take advantage of its convenient reporting functions.

PHP 5.2.x on Fedora 13

Tuesday, June 22nd, 2010

Not all of us are using PHP apps that are ready for PHP 5.3, so we need to rebuild PHP 5.2.x for some newer OS’s. Unfortunately, trying to rebuild the PHP 5.2.13 SRPM for Fedora 11 (the last Fedora to use PHP 5.2.x), on Fedora 13 doesn’t work as-is. The “configure” file ends up broken, and running it produces an endless stream of errors, starting with:

cat: confdefs.h: No such file or directory
./configure: line 387: ac_fn_c_try_run: command not found
...

It took me a while of looking around, but the solution was found on the Ubuntu bug tracker, specifically in the comment #17 by Arkadiusz Miƛkiewicz, which pointed to a PLD patch for the same issue. Patching the Fedora 11 SRPM with that patch (needs some fuzz) makes it build properly.