Quick PHP Debugging with FirePHP
Recently when browsing past issues of php|architect magazine, I came across mention of a Firefox add-on called FirePHP. For those who have not heard of it, FirePHP is both a Firefox add-on and a PHP library used to send messages to the Firebug console.
Installation of FirePHP was simple enough – install the add-on either through Mozilla or directly from the FirePHP download page. Once Firefox is restarted, firephp.org will redirect you to a page on how to install FirePHPCore, the library that accesses the Firebug console. PEAR users like myself get an easy install, and can easily start debugging with a simple include:
require_once('FirePHPCore/fb.php');
There is an object-oriented approach that can be taken with the FirePHP.class.php file, or static methods can be used in the fb.php file. The quick log-and-debug nature of the FB class makes it very easy to begin using right away. However, the more structured approach of the class file allows for some pretty interesting techniques for server embedding of FirePHP. Check out the blog of FirePHP creator Christoph Dorn for some examples of embedding FirePHP in your application.
For our example, a quick readout of $_SESSION or $_REQUEST may sometimes be handy:
$table = array();
$table[] = array('KEY','VALUE');
foreach($_REQUEST as $key=>$value)
{
$table[] = array($key, $value);
}
FB::table('Table Label', $table);
What you get is an nicely formatted table of your request variables and values, which can be helpful for AJAX scripts where calls echo or print_r may not be visible (not to mention those calls affect your application directly, where FirePHP does not have to).
Hopefully, you’ll try out FirePHP. In just the week I have started using it, FirePHP has already helped me quickly get out of several programming errors, and has done so in an easy-to-code and easy-to-read fashion. It is top-notch.


ShareThis