Share

From this page you can share FirePHP - The Firebug Extension for PHP to a social bookmarking site or email a link to the page.
Social WebE-mail
Enter multiple addresses on separate lines or separate them with commas.
FirePHP - The Firebug Extension for PHP
(Your Name) has forwarded a page to you from Ajaxonomy
(Your Name) thought you would like to see this page from the Ajaxonomy web site.

FirePHP - The Firebug Extension for PHP

Tagged:  

If you have been doing any Ajax development using PHP on the server side you are probably already using Firebug to find JavaScript errors. Wouldn't it be nice if you could also capture the server side PHP in the Firebug? Well, FirePHP makes it possible to do just that.

FirePHP acts as a logger and below is a code sample of how you would write to the log.

<?php

require('fb.php')

/* NOTE: You must have Output Buffering enabled via
         ob_start() or output_buffering ini directive. */

fb('Hello World'); /* Defaults to FB_LOG */

fb('Log message'  ,FB_LOG);
fb('Info message' ,FB_INFO);
fb('Warn message' ,FB_WARN);
fb('Error message',FB_ERROR);

fb('Message with label','Label',FB_LOG);

fb(array('key1'=>'val1',
         'key2'=>array(array('v1','v2'),'v3')),
   'TestArray',FB_LOG);

function test($Arg1) {
  throw new Exception('Test Exception');
}
try {
  test(array('Hello'=>'World'));
} catch(Exception $e) {
  /* Log exception including stack trace & variables */
  fb($e);
}

/* Will show only in "Server" tab for the request */
fb(apache_request_headers(),'RequestHeaders',FB_DUMP);

?> 

The key to using FirePHP is the use of the fb function which is available once you reference the fb.php file. In the function you pass in whatever you want to display and you can pass in variables that allow Firebug to capture the message as warnings, errors or logs. If you just want to log some information you would pass in FB_LOG or you can pass in FB_INFO for Firebug to display a message as info. If you pass in FB_WARN Firebug will treat it as a warning or if you pass in FB_ERROR it will treat it as an error.

You can read more about FirePHP and download the extension here.

I know I'm going to start really using this as it will help with development of many of the applications that we are working on for our Ajaxonomy Labs section. If you use FirePHP, I would love to hear your thoughts about it.