Using firePHP in firefox to debug PHP

Debugging PHP pages for a web application may be challenging. However, firePHP, a firefox extension can make debugging PHP pages very simple. Here are the steps to start debugging using firePHP.

1. Install firebug from https://getfirebug.com/downloads.

2. Install the firePHP extension from https://addons.mozilla.org/en-US/firefox/addon/firephp/.

The browser is now ready to receive the PHP logs that are sent from the server. Lets now look at how to write log statements on the PHP page.

3. Download the FirePHPCore library from http://www.firephp.org/HQ/Install.htm.

4. Extract the FirePHPCore-xxx folder from the zip and copy the FirePHPCore-xxx/lib/FirePHPCore folder to the apache web root folder.

5. Create a text file called test.php and add following contents

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<?php
#Include the FirePHP class
require_once(‘FirePHPCore/FirePHP.class.php‘);
#Start buffering the output. Not required if output_buffering is set on in php.ini file
ob_start();
#get a firePHP variable reference
$firephp = FirePHP::getInstance(true);
# we log today’s date as an example. you could log whatever variable you want to
$todays_date = date(‘l jS of F Y h:i:s A‘);
$firephp->log($todays_date, ‘Date‘);
?>

6. Start Firefox. Click on Firebug to open firebug window. Enable the console and net tabs. (very important, wont work without this).

7. In the firebug window, you should be able to see a ‘blue bug’. Click on it and make sure ‘FirePHP Enabled’ is checked.

8. copy the test.php file to web root and open the link in firefox opened in step 6,7.

9. You should be able to see the following line on the console

Date: Friday 1st of March 2013 07:04:01 PM

This is the Date variable that you logged in the PHP.

10. If you look at the Net tab, you should be able to see

X-Wf-1-1-1-1 -> 121|[{“Type”:”LOG”,”Label”:”Date”,”File”:”E:\xampp\htdocs\test.php”,”Line”:”12″},”Saturday 2nd of March 2013 11:06:02 AM”]|
The variable X-Wf-1-1-1-1 is what the PHP code library sends the browser. FirePHP extension looks for these variables.

This example shows how firePHPCore can be used to log statements and variables to the firePHP console. Use this method of debugging can speed up developmet.

2 thoughts on “Using firePHP in firefox to debug PHP”

  1. hi there..
    This is nice tutorial, explained crystal clear. I have been through massive tutorials about this FirePHP but i did not find any one useful due to lack proper explanation. May be It’s my fault because I’m a newbie of PHP. But i have found this tutorial more good and well explained but i have found some functions like getinstance(), trace() etc. in other tutorials, i have not found any of them here. If you don’t mind, would you please let me have layman explanation about those functions. Thanks in advance..

    Reply

Leave a Comment