FirePHP is a great tool for debugging PHP, and maintaining some level of control over your error handling. Also, it's a great tool for getting information about your variables, objects, etc. while your PHP code is executing. FirePHP requires only a small amount of setup and can be reused time and time again without tedious setups for each site on your server. This tutorial/example requires Firefox and Firebug, and FirePHP.
<?php
/**
* FirePHP setup.
* This code should only be found ONCE on your site, Add it to an include file.
* If site has single index.php (Magento, Drupal, etc.), call the include file once (there)
* using require_once(...);
*
* If you need this to be global, please replace $firephp with $GLOBALS['firephp'] everywhere!
* so: $GLOBALS['firebug'] = FirePHP::getInstance(true);
* and in your php code: $GLOBALS['firephp']->log('test of global firephp');
*/
require_once('/var/www/vhosts/includes/firephp/FirePHP.class.php');
$firephp = FirePHP::getInstance(true); //non-global
// Add allowed ip addresses below, comma-separated
$allowedIpArr = array('127.0.0.1', 'XX.XX.XX.XX');
if (in_array($_SERVER['REMOTE_ADDR'], $allowedIpArr)) {
$firephp->setEnabled(true);
}
else {
$firephp->setEnabled(false);
}
// Log all errors, exceptions, and assertion errors to Firebug
// NOTE! these may cause problems... use them with caution!
$firephp->registerErrorHandler($throwErrorExceptions=true);
$firephp->registerExceptionHandler();
$firephp->registerAssertionHandler($convertAssertionErrorsToExceptions=true, $throwAssertionExceptions=false);
?>
<?php
// Load Firephp from the include file in this site's root
require_once($_SERVER['DOCUMENT_ROOT'] . '/firephp_include.php');
// Make sure we know FirePHP is running by logging a message to the FirePHP
$firephp->info('Debugging using FirePHP');
$myvar1 = array(
array('test' => 'test1-value'),
array('test2' => 'test2-value'),
);
$firephp->fb($myvar1);
$firephp->log('This is a normal log message');
$firephp->warn('This is a warning message', 'My Warning Label');
$firephp->error('This is a error message');
?>
The image below shows the output of the example code above.

Add new comment