FirePHP: Introduction

FirePHP is a PHP library that integrates a variety of development tools and combines error reporting and print debugging with console logging to aid in PHP application development. Traditionally FirePHP has been used to only log from PHP to the Firebug Console.

PHP debugging approaches

When talking about debugging PHP code there are primarily four approaches:

  1. Error Reporting - PHP native and used to detect syntax errors and API usage violations.
  2. Print Statements - Deliberate var_dump() or print() statements by developer used to track execution flow and variables.
  3. Logging - Deliberate logging to a file or other facility used to track events, execution flow and variables.
  4. Interactive Debugging - PHP extension used by developer to directly interact with a running script to track live variable state.

Using Error Reporting, Print Statements and Logging for debugging is relatively starightforward while getting Interactive Debugging to work is more involved.

See IBM: Debugging techniques for PHP programmers for introduction

Why FirePHP

The goal of FirePHP is to combine the best aspects of all four debugging approaches in an easy to install and use package.

By having all error and selected internal information about an application readily available a developer may save significant amounts of time learning, tracking and maintaining program logic.

Traditional PHP debugging solutions have primarily focused on one debugging approach at a time. FirePHP combines Error Reporting and Print Statements with Logging in an open architecture and protocol designed to support direct integration into debugging clients and integrated development environments.

DeveloperCompanion is a new client with full support for FirePHP and is being used to pioneer a combined approach to debugging where relevant information is gathered from many sources, combined and presented in a uniform interface.

DeveloperCompanion replaces the existing FirePHP Extension to facilitate logging to the Firebug Console.

The addition of Xdebug as a source of internal information is planned.

FirePHP History

FirePHP was first developed by Christoph Dorn in 2007 and has since grown to 600,000+ downloads and ~70,000 active daily users according to Mozilla Add-ons.

Christoph still develops, maintains and supports FirePHP and is the primary sponsor of the project.

FirePHP was designed to log from server-side PHP code to the Firebug Console facilitated by a FirePHP Server Library and FirePHP Firefox Extension. FirePHP gained popularily on a larger scale when Zend Framework 1.6 shipped with native FirePHP support in September 2008. Many frameworks have added FirePHP support to make it easier to use FirePHP for their users.

With the 1.0 Release the project brings many new features and is shifting 100% of it's focus to further developing the Server Library only while allowing any client that implements the appropriate open protocols to access the data and services the FirePHP Server Library provides. The first client to be fully compatible with the 1.0 Release is DeveloperCompanion which is designed to replace the FirePHP Firefox Extension for existing users. An open-source client called FireConsole is under development and will be released once the underlying open source libraries in FirPHP Companion stabilize.

FirePHP Protocol

FirePHP does not define its own protocol but rather uses wildfire for server-client communication and insight for wrapping data into static, language agnostic, JSON-based object graphs ready for transport and storage.

Client initiated communication for specific resources as well as execution generated data sent via HTTP response headers is supported. All communication is out-of-band (to the application) meaning it will not interfere with the normal functioning of the application.

Integrating FirePHP

FirePHP consists of a PHP library that is simply included at the beginning of any PHP script and configured inline or via a configuration file. See Install for detailed instructions. By default FirePHP is disabled (to minimize overhead) and will only be activated if an authorized client is detected. The intent is to integrate FirePHP into an application and deploy it along with the application (leaving all logging statements in place) to all environments. FirePHP supports troubleshooting issues on production systems in a safe and reliable manner.

Example

define('INSIGHT_IPS', '*');
define('INSIGHT_AUTHKEYS', 'client-auth-key');
define('INSIGHT_PATHS', dirname(__FILE__));
define('INSIGHT_SERVER_PATH', '/index.php');
require_once('phar://firephp.phar/FirePHP/Init.php');

$inspector = FirePHP::to('page');
$console = $inspector->console();

$console->log('Hello World');

This example logs a Hello World message to the Firebug Console.

See Install for installation instructions.

See API for a complete reference of all API features.

License

FirePHP is licensed under the MIT License.

Composition

The FirePHP Server Library combines components from several projects:

See Open Source for more information.

Support

The FirePHP Project is supported via the community forums and developer mailing list. Commercial support is also available by Christoph Dorn.

News

You can follow FirePHP on twitter: http://twitter.com/firephplib

In-depth FirePHP news and tutorials are available on Christoph's blog: http://www.christophdorn.com/Blog/category/firephp/