Mar 302011
 

1. Installation
Create a file “package.json” with the following content (set uid of your package)
{
"uid": "(your package uid)"
}

Create a file called “package.json” with with content as example below (add IP restriction or/and keys), the example gives unlimited access.
{
"cadorn.org/insight/@meta/config/0": {
"allow": {
"ips": [ "*" ],
"authkeys": [ "*" ]
}
}
}

Download the server library, the easiest is to use phar file, and set up your virtual host:
<VirtualHost *:80>
php_value auto_prepend_file phar:///var/www/firePHP_1.0/firephp.phar/FirePHP/Init.php
SetEnv INSIGHT_CONFIG_PATH /var/www/firePHP_1.0/package.json,/var/www/firePHP_1.0/credentials.json
...
</VirtualHost>

Install client plugin (FirePHP Companion) in your web browser,

2. Page Context
$inspector = FirePHP::to("page");
$console = $inspector->console();
$console->log("Hello World");

3. Request Context
$inspector = FirePHP::to("request");
$console = $inspector->console();
$console->log("Hello World");

4. Controller Context
$inspector = FirePHP::to("request");
$console = $inspector->console();
$console->log("Hello World");
$controller = FirePHP::to("controller");
$controller->triggerInspect()


5. Package Context

$package = FirePHP::to("package");
$package->addQuickLink("Link 1", "http://www.firephp.org/");
$package->addQuickLink("Link 2", array(
"target" => "window", // tab (default), window or hidden
"url" => "http://www.firephp.org/"
));


$controller = FirePHP::to("controller");
$controller->triggerInspect();

6. Basic API
$inspector = FirePHP::to("request");
$console = $inspector->console();
$variable = "Hello World";

$console->log($variable);
$console->info($variable);
$console->warn($variable);
$console->error($variable);

// Message Label
$console->label("My label")->log($variable);

// Table
$header = array("Column 1 Heading", "Column 2 Heading");
$table = array(
array("Row 1 Column 1 Value", "Row 1 Column 2 Value"),
array("Row 2 Column 1 Value", "Row 2 Column 2 Value"),
);
$console->table("Table", $table);
$console->table("Table with header", $table, $header);

// Stack Traces
$console->trace("My stack trace");

// Group
$group = $console->group("myGroup", "Group Title")->open();
$console->info("Hey!, I am in a group");
$console->error("I am in a group too!");
$group->close();


// Console controller
$controller = FirePHP::to("controller");
$controller->triggerInspect();

7. Conditional Logging

$inspector = FirePHP::to("request");
$console = $inspector->console();

$console->on("Show warnings")->warn("I am warning you!");

// Console controller
$controller = FirePHP::to("controller");
$controller->triggerInspect();

8. Engine API
$inspector = FirePHP::to("request");
$console = $inspector->console();
$engine = FirePHP::plugin("engine");
// Send all exceptions and errors to a specific console
$engine->onError($console);
$engine->onAssertionError($console);
$engine->onException($console);
// Console controller
$controller = FirePHP::to("controller");
$controller->triggerInspect();

// Handle manually
try {
throw new Exception("Hello, I am a manually handled exception");
} catch(Exception $e) {
$engine->handleException($e);
}

throw new Exception("Test Exception");

9. FirePHP API
$inspector = FirePHP::to("request");

// Log p() messages to the provided console
$firephp = FirePHP::plugin("firephp");
$inspectorConsole = $inspector->console("InspectorConsole");
$firephp->declareP($inspectorConsole, true);

$variable = array("key"=>"value");
p($variable); // or
p($inspector, "Inspector");

// Log the current FirePHP version to a FirePHP console.
$versionConsole = $inspector->console("Version Console");
$firephp->logVersion($versionConsole);

// Send information about the PHP environment to an Environment console.
$envConsole = $inspector->console("Environment");
$firephp->recordEnvironment($envConsole);

// Console controller
$controller = FirePHP::to("controller");
$controller->triggerInspect();

//Send all errors and exceptions to a Problems console.
$problemConsole = $inspector->console("Problem Console");
$firephp->trapProblems($problemConsole);

throw new Exception("I am your problem");

Mar 302011
 

1. FirePHP 0.5 – Installation
1. Dwonload The Server Library and include it
2. require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");
Or find a plugin for your framework.

2. Object Oriented API
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");
$firephp = FirePHP::getInstance(true);
$firephp->log("Hello World");

3. Procedural API
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/fb.php");
fb("Hello World");
fb("Hello World", "Label");

4. Options
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

// Defaults:
$options = array("maxObjectDepth" => 5, // Maximum depth to traverse objects.
"maxArrayDepth" => 5, // Maximum depth to traverse arrays.
"maxDepth" => 10, // Maximum depth to traverse mixed arrays/objects.
"useNativeJsonEncode" => true, // Set to FALSE to use JSON encoder included with FirePHPCore instead of json_encode().
"includeLineNumbers" => false); // Include File and Line information in message

$firephp = FirePHP::getInstance(true);
$firephp->setOptions($options);
$firephp->log("Hello World");

5. Log level
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);
$firephp->log("Logs a message to firebug console.");
$firephp->info("Logs a message to firebug console and displays an info icon before the message.");
$firephp->warn("Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise.");
$firephp->error("Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count.");
// or
$firephp->fb("Log with fb() method", FirePHP::LOG);
$firephp->fb("Info with fb() method", FirePHP::INFO);
$firephp->fb("Warning with fb() method", FirePHP::WARN);
$firephp->fb("Error with fb() method", FirePHP::ERROR);

6. Dump
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);
$firephp->dump("array",array("key"=>"value"));
$firephp->dump("firePHP",$firephp);

7. Trace
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);
$firephp->trace("Trace Label");

8. Groups
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);
$firephp->group("Test Group");
$firephp->log("Hello World");
$firephp->groupEnd();

$firephp->group("Collapsed and Colored Group",
array("Collapsed" => true,
"Color" => "#FF00FF"));
$firephp->log("Hello World");
$firephp->groupEnd();

9. Tables
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);

$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");

$firephp->table("Table Label", $table);

10. Exception Handling
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);
$firephp->registerErrorHandler( $throwErrorExceptions=false);
$firephp->registerExceptionHandler();
$firephp->registerAssertionHandler( $convertAssertionErrorsToExceptions=true, $throwAssertionExceptions=false);

throw new Exception("Test Exception");
// or manually
try {
throw new Exception("Test Exception");
} catch(Exception $e) {
$firephp->error($e);
}

11. Disabling firePHP
require_once("./FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php");

$firephp = FirePHP::getInstance(true);
$firephp->log("Hello");
$firephp->setEnabled(false);
$firephp->log("Hello again");

Feb 052009
 

FirePHP is a plugin for the Firebug Firefox extension. Similar to Y!Slow, the plugin hooks into Firebug and provides extra functionality.

Unlike Y!Slow, FirePHP does not create a “new tab” in Firebug. All it does is parse custom HTTP headers and print them out in the Firebug “console” tab. Since the messages have to be sent out as HTTP headers I have never been a great fan of FirePHP, simply because most of the time I would want to inject something to the console tab is looong after I have sent out the initial headers.

After few months of “ignoring the hype” I had to give it a try. My initial testing was just as I expected: This sucks. I had to reorganize all my code so I could send out the FirePHP headers – however doing so had a major impact on when the user got anything back from the page he requested, something I really do not want to do. Bye bye FirePHP.

Here at Redpill Linpro we use Symfony for most of our projects, which uses Output Buffering a lot. Hello FirePHP.

The benefits of using output buffering, among other things, is you can send out headers at any time in the script. That means, we can throw FirePHP messages even in the footers of pages.

So, what is it good for and how do we use it?

AJAX responses have always been a PITA to debug. In some cases we simply do not have any way to print out debug information without destroying the response it self, so we have to turn to flat-file-logging.. which symfony fills up with tons of useless information making it hard to browse. Using FirePHP however you can “print out” whatever information you want, directly to the Firebug console!

Other things like rendering timers, sql queries, backtraces and background info on error pages is great to throw into FirePHP.

To use FirePHP with Symfony you will have to install the Firefox extension itself (duhh) and then the PHP “client library”.
Note: To see the FirePHP messages you will have to enable the “Console”, “Script” and “Net” panels in Firebug!


$ symfony plugin:install sfFirePHPPlugin

The client library is oddly complicated but does do the job. It offers several “importance levels”, which get color coded, such as warnings, info and error. Furthermore you can group messages for easier access.

To, for instance, show the “Symfony Debug toolbar” timers for _all_ requests (including error pages and AJAX responses) you can add to the ProjectConfiguration class:

public function setup()
{
/* [snip] */
if ($this-&gt;environment === "dev")
{
$this-&gt;getEventDispatcher()-&gt;connect("response.filter_content", array($this, "responseFilterContent"));
$this-&gt;getEventDispatcher()-&gt;connect("application.throw_exception", array($this, "responseFilterContent"));
}

public function responseFilterContent(sfEvent $event, $content = null)
{
$fp = sfFirePHP::getInstance(true);

$fp-&gt;group("Debug timers");
foreach(sfTimerManager::getTimers() as $nfo =&gt; $timer)
{
$fp-&gt;info(sprintf("%s: %.2fms (%d calls)", $nfo, $timer-&gt;getElapsedTime() * 1000, $timer-&gt;getCalls()));
}
$fp-&gt;groupEnd();

return $content;
}

That should give you a nice little groupped “Debug timers” in the Firebug Console using the “dev” frontend \o/.

FirePHP screenshot

You always have FirePHP at your fingertips, to log to it just add

FirePHP::getInstance(true)->info("Hello world! :D ");

Happy debugging!.