TAAT Technologie Cyfrowe

Zend Framework Tutorial

Debugging and database profiling with FirePHP

FirePHP is very useful FireBug extension and since Zend Framework v.1.7 is natively supported.

All you need is to install FireBug and FirePHP Firefox extensions and configure logging in your Bootstrap.php.

Doctrine database profiling with FirePHP requires additonal class /library/Imind/Profiler/Doctrine/Firebug.php which can be downloaded from Imind-PHP project page.

The Bootstrap

In your Bootstrap.php add setupFirePHP() method:

 * setup FirePHP
 * @access public static
 * @param bool $enable Enable or disable logging
 * @return null
public static function setupFirePHP($enabled = true) {
    $writer = new Zend_Log_Writer_Firebug();
    $logger = new Zend_Log($writer);
    // add FirePHP logger to the registry
    Zend_Registry::set('logger', $logger);

    if ($enabled) {
        // setup Doctrine profiling
        $profiler = new Imind_Profiler_Doctrine_Firebug('All DB Queries: ');

To start logging and database profiling, add one line to setupDatabase() method:

 * Setup Database
 * @access public static
 * @return null
public static function setupDatabase() {

    // or if you don't need database in Bootstrap
    // self::$frontController->registerPlugin(new My_Controller_Plugin_Doctrine());

To display all profiling result in FireBug console, add one line at the end of sendResponse() method:

// Display Doctrine Profiling information in Firebug

How do we use it?

FirePHP is enabled/disabled via global debug settings in .htaccess, or via $enabled boolean parameter of setupFirePHP() method.

To display info message in FireBug console, use Zend_Registry::get('logger')->err('My test error message');, Zend_Registry::get('logger')->log($myarray); and so on. Check FirePHP Headquarters for more information.

Let’s simplify this notation by adding fb() function (not method!) at the end of the Bootstrap.php (after ending bracket of the Bootstrap class):

 * FirePHP debugging shortcut
function fb($message, $label = null)
    $logger = Zend_Registry::get('logger');
    if ($label != null) {
        $logger->log($label . ':', Zend_Log::INFO);
    $logger->log($message, Zend_Log::DEBUG);

Now we can use FirePHP debugging like this: fb($myvar) or fb($myvar, 'My label');

Additional reading