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.

This is the best thing ever in the history of the universe!
Firefox 2.0.0.13 says the extension isn't compatible, but once that's resolved, this will be very, very nice to have.

It is good but a little bit late for firefox

firebug is essential for any webmaster

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <div> <blockquote> <object> <embed> <img> <param>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.