FirePHP in Scorpio

Posted by Dave Redfern (Writer), News on 17 Oct 2008 @ 14:50

FirePHP is a Firebug extension for Firefox 3. Firebug (for those that don't yet use it) is perhaps the most useful debugging and development plugin you can get for Firefox. It basically allows you to inspect pretty much anything including elements (including generated items from scripts), ajax requests, javascript debugging, CSS debugging etc.

FirePHP extends Firebugs features to allow messages to be sent from PHP applications to the Firebug console. This is useful for seeing what happens at the server side during an ajax request or if you don't particularly want to mess up the presentation with echo()d comments.

The FirePHP implementation within Scorpio hooks into the systemLog as a writer. The writer maps the systemLog message to the appropriate FirePHP message. As the implementation is a standard writer object, it can have a defined systemLogFilter. Using it is extremely simple, pick a part of the mvc system to add logging to (either in the distributor or in the site mvcController class and then add:

// in baseAdminSite -> libraries -> mvcDaoController.class.php
// within addAjaxControls()
function addAjaxControls() {
    systemLog::getInstance()->setWriter(
        new systemLogWriterFirePhp(
            new systemLogFilter(systemLogLevel::ALWAYS, systemLogLevel::WARNING)
        )
    );
    // rest of method...
}

With that done any systemLog calls will be sent to the Firebug console. The log range can be set to whatever you want, but should not be used in a production environment.

Some notes:

As the FirePhp writer is a log writer, it is already receiving formatted messages, therefore it does not make use of the table, dump or other fancy features.

As the DEBUG logLevel automatically causes SQL queries to be logged it is strongly advised to NOT set the loglevel to debug on this writer.

As potentially sensitive information could be displayed; if the system is set to production mode NO information will be logged to Firebug at all - all logging is ignored.

Finally: FirePHP requires output buffering as the messages are sent as headers. ob_start() is called within the writer automatically to ensure that this is the case, however this could potentially cause issues with some template engines if they expect to be the only system using output buffering. Testing with Smarty has shown no ill effects of this.

If output has already started, then systemLogWriterFirePhp will throw an exception. As writer exceptions are not caught or handled this may cause the system to stop.

< Return to article