• Home

Logo

Navigation
  • Home
  • Articles
    • Content Writing
    • Design
    • General
    • Internet Marketing
    • Social Media
    • Tools and Tips
    • Usability
    • Web Hosting Articles
  • Tutorials
    • AJAX Tutorials
    • ASP Tutorials
    • C# Tutorials
    • CGI and Perl Tutorials
    • CSS Tutorials
    • Flash Tutorials
    • HTML Tutorials
    • Illustrator Tutorials
    • Java Tutorials
    • JavaScript Tutorials
    • Linux Tutorials
    • Miscellaneous Tutorials
    • MySQL Tutorials
    • Photoshop Tutorials
    • PHP Tutorials
    • Python Tutorials
    • Wireless Tutorials
    • WordPress Tutorials
    • XML Tutorials
  • Scripts
    • AJAX Scripts
    • ASP Scripts
    • ASP.NET Scripts
    • CGI & Perl Scripts
    • Flash Scripts
    • Java Scripts
    • JavaScript Scripts
    • PHP Scripts
    • Python Scripts
    • Remotely Hosted
    • Tools and Utilities
    • XML Scripts
  • Answers
  • Online Services
  • Tools

Debugging PHP with Firebug and FirePHP

By Akash Mehta | on May 21, 2008 | 3 Comments
PHP Tutorials
  • Tweet
  • Share
  • Tweet
  • Share

FirePHP is a plugin for Firebug, the web development plugin for Firefox, that allows PHP scripts to talk to a Firebug panel. FirePHP installs alongside Firebug, and provides a simple PHP library to bridge the two. FirePHP provides a window of insight into your PHP applications, with a simple debugging interface that won’t interfere with your page content. If you already use Firebug on PHP-powered applications, FirePHP is definitely worth a look. Here’s a quick guide to getting started.

FirePHP is implemented as a native Firefox extension, and is available from Mozilla Addons. After a basic setup procedure, you can start printing everything from status messages to multi-dimensional arrays straight to your Firebug console. FirePHP achieves this using extension HTTP headers – in particular, X-FirePHP-Data headers in the response.

The PHP library provides a function, fb(), which handles sending data across to the client side. From here, you simply open up your Firebug console, and your data is displayed in a highly functional manner.

To get started with FirePHP, grab the extension from Mozilla Addons

  • download fast and furious 4 HD

and the core library from the FirePHP project page (the “Download” link). You’ll need to install Firebug first, then the FirePHP Firefox addon. Next we get to the PHP library – either add the “FirePHPCore” folder to somewhere in your include_path, or just pop it into your script directory, and include it:

require('FirePHPCore/fb.php');

Remember to change the relative path as required (no pun intended). Then, simply call the fb() function anywhere in your code, passing a single argument – the info you want to send to your FirePHP console. Here are some examples:

fb('The value of $var is '.$var);
fb('Just logging this event.',FirePHP::LOG);
fb('Error in the email module.',FirePHP::ERROR);
fb($_SERVER, '$_SERVER array', FirePHP::LOG);

try {
  throw new Exception('Exception');
} catch(Exception $e) {
  fb($e);
}

As you can see, we can output basic messages, use Firebug’s standard styles to identify message importance (also, INFO and WARN), output labelled assocative arrays, and even debug exceptions – FirePHP will display a neat little stack trace.

Remember that this information is sent via headers, so it needs to be output before any of your HTML. If you’re using a framework with view templates, this is probably not an issue, but otherwise, you can get around the problem by using output buffering. Just run this line somewhere near the beginning of your script execution:

ob_start();

This will initialise output buffering, so that any HTML you output is held up till the end of script execution (or till the next call to ob_flush() and derivatives). Calling the fb() function will then work fine any time before the end of your script, as the headers will be flushed immediately. (Alternatively you can use php_flag output_buffering on in your .htaccess / apache virtual host configuration.)

FirePHP has all sorts of neat tips and tricks – just check out the quick start guide and protocol reference. If you use the Zend Framework, have a look at the Zend library for FirePHP; similar libraries exist for Symfony and Prado as well.

Share this story:
  • tweet

Author Description

3 Responses to “Debugging PHP with Firebug and FirePHP”

  1. July 21, 2008

    David Dashifen Kees Log in to Reply

    I’ve always hated that the fb() function hasn’t been encapsulated into a class; especially a PHP5 class. Being able to include it via the __autoload() function would be fantastic!

  2. July 21, 2008

    Christoph Log in to Reply

    There is a class for it. See: http://code.google.com/p/firephp/source/browse/trunk/Libraries/FirePHPCore/lib/FirePHPCore/FirePHP.class.php
    It is included in the PHP library you can download from http://www.firephp.org/
    If this does not meet your needs, please send in your feedback in the discussion group (http://groups.google.com/group/FirePHP) and we can find a solution for you.

  3. September 15, 2008

    doez Log in to Reply

    thank’s for information

You must be logged in to post a comment.

Connect With Us

RSSSubscribe 0Followers 494Likes
  • Popular
  • Recent
  • Comments
  • Creating Energy Spheres in Photoshop

    Apr 15, 2008 - 96 Comments
  • Easy Screen Scraping in PHP with the Simple HTML DOM Library

    Aug 6, 2008 - 20 Comments
  • Calculating date difference more precisely in PHP

    Mar 7, 2008 - 13 Comments
  • When Does Hosting Your Website in the Cloud Make Sense?

    Oct 8, 2010 - 2 Comments
  • Fun with the Microsoft Managed Extensibility Framework Part 2

    Oct 6, 2010 - 0 Comment
  • Fun with the Microsoft Managed Extensibility Framework Part 1

    Sep 22, 2010 - 0 Comment
  • Website Management on the go with the iPad

    I appreciated your post, but I was looking for something I didn't...
    November 24, 2012 - drmoderator
  • Creating Energy Spheres in Photoshop

    I'm a little stuck down here especially at the step of creating the...
    November 23, 2012 - sarah
  • Running background processes in PHP

    Can you give an example? As see it, you can use this only when you...
    November 16, 2012 - Shaked Klein Orbach
Developer Resources
  • Tutorial Directory
  • Learn HTML
  • Learn PHP
  • Learn CSS
  • Learn AJAX
  • Learn JavaScript
  • Learn Pear
  • White Papers
  • Resources
    • NetVisits Web Directory
    • Realtor Pixels
    • Answers On The Run
    • Ask A Geek
  • Recent Posts

    • When Does Hosting Your Website in the Cloud Make Sense?
    • Fun with the Microsoft Managed Extensibility Framework Part 2
    • Fun with the Microsoft Managed Extensibility Framework Part 1
    • Website Management on the go with the iPad
    • Code Contracts in C# 4.0 – Part 1

    Calendar

    May 2013
    M T W T F S S
    « Oct    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Recent Comments

    • drmoderator on Website Management on the go with the iPad
    • sarah on Creating Energy Spheres in Photoshop
    • Shaked Klein Orbach on Running background processes in PHP
    • Thomas Cuvillier on How To Upload Files Using PHP
    • rizal aditya on Extracting text from Word Documents via PHP and COM
    • Home
    © 2003 - 2013 DeveloperTutorials.com. All Rights Reserved. Privacy Policy.