Feb 052009
 

FirePHP is a plugin for the Firebug Firefox extension. Similar to Y!Slow, the plugin hooks into Firebug and provides extra functionality.

Unlike Y!Slow, FirePHP does not create a “new tab” in Firebug. All it does is parse custom HTTP headers and print them out in the Firebug “console” tab. Since the messages have to be sent out as HTTP headers I have never been a great fan of FirePHP, simply because most of the time I would want to inject something to the console tab is looong after I have sent out the initial headers.

After few months of “ignoring the hype” I had to give it a try. My initial testing was just as I expected: This sucks. I had to reorganize all my code so I could send out the FirePHP headers – however doing so had a major impact on when the user got anything back from the page he requested, something I really do not want to do. Bye bye FirePHP.

Here at Redpill Linpro we use Symfony for most of our projects, which uses Output Buffering a lot. Hello FirePHP.

The benefits of using output buffering, among other things, is you can send out headers at any time in the script. That means, we can throw FirePHP messages even in the footers of pages.

So, what is it good for and how do we use it?

AJAX responses have always been a PITA to debug. In some cases we simply do not have any way to print out debug information without destroying the response it self, so we have to turn to flat-file-logging.. which symfony fills up with tons of useless information making it hard to browse. Using FirePHP however you can “print out” whatever information you want, directly to the Firebug console!

Other things like rendering timers, sql queries, backtraces and background info on error pages is great to throw into FirePHP.

To use FirePHP with Symfony you will have to install the Firefox extension itself (duhh) and then the PHP “client library”.
Note: To see the FirePHP messages you will have to enable the “Console”, “Script” and “Net” panels in Firebug!


$ symfony plugin:install sfFirePHPPlugin

The client library is oddly complicated but does do the job. It offers several “importance levels”, which get color coded, such as warnings, info and error. Furthermore you can group messages for easier access.

To, for instance, show the “Symfony Debug toolbar” timers for _all_ requests (including error pages and AJAX responses) you can add to the ProjectConfiguration class:

public function setup()
{
/* [snip] */
if ($this->environment === "dev")
{
$this->getEventDispatcher()->connect("response.filter_content", array($this, "responseFilterContent"));
$this->getEventDispatcher()->connect("application.throw_exception", array($this, "responseFilterContent"));
}

public function responseFilterContent(sfEvent $event, $content = null)
{
$fp = sfFirePHP::getInstance(true);

$fp->group("Debug timers");
foreach(sfTimerManager::getTimers() as $nfo => $timer)
{
$fp->info(sprintf("%s: %.2fms (%d calls)", $nfo, $timer->getElapsedTime() * 1000, $timer->getCalls()));
}
$fp->groupEnd();

return $content;
}

That should give you a nice little groupped “Debug timers” in the Firebug Console using the “dev” frontend \o/.

FirePHP screenshot

You always have FirePHP at your fingertips, to log to it just add

FirePHP::getInstance(true)->info("Hello world! :D ");

Happy debugging!.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>