Recently I have add a new entry to my company wiki about using FirePHP with CodeIgniter framework. I was very excited to find out that FirePHP Core Library now available in PHP4 and by referencing to an old entry Fire Ignition, I quickly create a CI wrapper that allows developer to embed FirePHP codes in their existing CI projects.
Although this page provide detail coverage on FirePHP, it mainly focus on integrating with Code Igniter, PHP4 MVC framework used for Central2. All setup and examples usage are also in PHP4.
FirePHP is an addon for FireBug, which is an extension for Firefox browser. It enables you to log to your Firebug Console using a simple PHP method call. All data is sent via response headers and will not interfere with the content on your page.
FirePHP is ideally suited for AJAX development where clean JSON and XML responses are required.
For a long time, debugging in PHP is a very cumbersome task and sometime inefficient. FirePHP provides Visual Studio like ‘trace’ and ‘watch’, which is not comprehensive but a big steps for PHP development lifecycle.
One major benefit of FirePHP is it is possible to debug a live website/web application. Specific PHP codes embedded in PHP pages that will only get triggered when client is running with FirePHP plugin installed, which will send debug messages to client console window.
Following statements are yet to be tested and verified:
-
Direct impact on performance in relation of amount of debugging message output in 1 instance.
-
All users with FirePHP installed will be able to see those debug messages.
-
Firefox browser http://www.mozilla.com/firefox/
-
FireBug extension http://getfirebug.com/ (alternatively, https://addons.mozilla.org/en-US/firefox/addon/1843/)
-
FirePHP extension http://www.firephp.org/
-
PHP 5This is no longer the case. A PHP4 version of FirePHP core library has been made available
Below is the setup environment of tested in:
-
PHP 4.4.x
-
Code Igniter 1.7.1 http://codeigniter.com/
-
Download FirePHP Core Library and find
FirePHP.class.php4file -
Add a new setting in configuration file (config.php)
$config['fire_php_enabled'] = true;
-
Create a new folder in Code Igniter Library folder: firephp-[VERSION_NUMBER] and have following files in this folder
-
firephp.php : rename of
FirePHP.class.php4 -
firephp_fake.php : FirePHP_FAKE class file with all attributes and properties but no implementation
-
fireigniter.php : a communicator class used by controller. This class help controller determine to load firephp.php or firephp_fake.php depends on configuration setting.
-
class fireigniter { /** * Constructor */ function fireigniter() { //-- Load CodeIgniter Resources $CI =& get_instance(); //-- Check Configuration if ($CI->config->item('fire_php_enabled') == true) { //-- Load FirePHP $CI->load->library('firephp-0.3.1/firephp'); } else { //-- Load Fake FirePHP, an empty class and name instance 'firephp' instead of 'firephp_fake' $CI->load->library('firephp-0.3.1/firephp_fake', 'firephp'); } } }//END class

-
May require output buffering either
-
switch on in php.ini (as mentioned in
http://activecodeline.com/setting-up-firephp-with-codeigniter/http://www.firephp.org/HQ/Learn.htm)
-
You are almost done. Now you need to be sure that PHP’s output buffering setting is turned on. I use WAMP package so turning this option on means clicking on WAMP icon in tray area, then selecting PHP > PHP Settings > Output buffering
-
or use inline command
ob_start();
-
Ensure Firebug ‘Net’ and ‘Console’ panels are enabled.

Priority Logging Messages
These logging methods follow the four Firebug logging priorities. Add an optional label as a second argument to any of these methods.
$this->firephp->log($message, $label); //.. or $this->firephp->fb($message, $label, FirePHP_LOG);
$this->firephp->info($message, $label); //.. or $this->firephp->fb($message, $label, FirePHP_INFO);
$this->firephp->warn($message, $label); //.. or $this->firephp->fb($message, $label, FirePHP_WARN);
$this->firephp->error($message, $label); //.. or $this->firephp->fb($message, $label, FirePHP_ERROR);
Dumping Variable
$this->firephp->fb($variable, $key);

Table
You can log tables of information. Firebug will display the Table Label and allow the user to toggle the display of the table. The first row of the table is automatically used as the heading and the number of columns is dynamically determined.
$table = array(); $table[] = array('Col 1 Heading','Col 2 Heading'); $table[] = array('Row 1 Col 1','Row 1 Col 2'); $table[] = array('Row 2 Col 1','Row 2 Col 2'); $table[] = array('Row 3 Col 1','Row 3 Col 2'); $this->firephp->table($label, $table); //.. or $this->firephp->fb($table, $label, FirePHP_TABLE);

Following APIs has been tested and unable to perform as its documented.
Traces
$this->firephp->trace($message, $label); //.. or $this->firephp->fb($message, $label, FirePHP_TRACE);
Dump
$this->firephp->dump($key, $variable); //.. or $this->firephp->fb($variable, $key, FirePHP_DUMP);
class welcome extends Controller { function Welcome() { parent::Controller(); $this->load->library('firephp-0.3.1/fireigniter'); } function index() { $this->firephp->fb("entering 'index' function", FirePHP_INFO); $var = $this->config; $this->firephp->fb($var, 'Current Configuration', FirePHP_INFO); $number = rand(); $this->firephp->fb($number, 'Random Generated Number', FirePHP_INFO); echo 'Random Number is: '.$number; if($number % 2 == 0) { $this->firephp->fb($number, '$number before double_it()', FirePHP_INFO); $number = $this->double_it($number); $this->firephp->fb($number, '$number after double_it()', FirePHP_INFO); } else { $this->firephp->warn("Odd random number detected."); } if($number > 20000) { $this->firephp->error("Number is greater than 20000. Function terminated."); $this->firephp->fb($number, 'Number', FirePHP_ERROR); return; } echo '<br>'; echo 'Output Number is: '.$number; $this->firephp->info("reaching to the end of 'index' function"); return $number; } function double_it($n) { $output = $n * 2; $message = "$n x 2 = $output"; $this->firephp->fb($message, FirePHP_LOG); return $output; } }
Route 1: Random Number is Even and result is smaller than 20,000

Route 2: Random Number is Even and result is bigger than 20,000

Route 3: Random Number is Odd and result is smaller than 20,000

Route 4: Random Number is Odd and result is bigger than 20,000

FirePHP 0.3.1 Library Packpage for CodeIgniter
FirePHP Wiki – Code Igniter
http://www.firephp.org/Wiki/Libraries/CodeIgniter
Debugging a CodeIgniter application with FirePHP
http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/
Setting up FirePHP with CodeIgniter
http://activecodeline.com/setting-up-firephp-with-codeigniter/
FirePHP :: Add-ons for Firefox