Strange Symphonies The best way to predict the future is to invent it

7Feb/090

Making FirePHP Accessible to Every PHP Page

I heart FireBug. I loved FireBug so much, I even made a simple Ruby on Rails plugin to log to FireBug, called FireBug Logger.

It was rudimentary, but it did its job. Lucky for me, a similar project exists in the PHP world, appropriately labelled FirePHP.

FirePHP

FirePHP is bit fancier, in that it can format the output that is sent to the FireBug console. But because of this feature, it requires to be installed as a Firefox extension.

This post will not discuss on the benefits of using FirePHP, or how to install it. There are lots more material available out there on that.

Making FirePHP Easily Accessible

Sadly to get FirePHP available to every PHP script, you are required to call the code to load FirePHP (fb.php). But this is not necessarily true.

In your php.ini, there is an option called auto_prepend_file which will automatically include a PHP file before executing the requested PHP file.

So with this can call load FirePHP prior to any execution, and thus making it accessible via any script that is executed.

Lets enable the auto_prepend_file and give it a value to another PHP file.

auto_prepend_file = /Users/aizat/src/firephp/firephp.php

Don't forget to restart your Apache, else your changes won't be applied!

Now inside /Users/aizat/src/firephp/firephp.php, I will require the main FirePHP library like so:

<?php

require_once('lib/FirePHPCore/fb.php');

if (php_sapi_name() != 'cli' &amp;&amp; ini_get('output_buffering') == false) {
    ob_start();
}?>

Make sure that the require_once on line 3 points to the location of the fb.php.
require_once('lib/FirePHPCore/fb.php');

Testing

Now lets test it with a very simple file. Create a php file and dump this inside:

<?php
fb("auto_prepend_file successfully worked!", FirePHP::LOG);
?>

Open the file in your web browser, and it should load successfully!

There you have it, easy debugging without manually requiring the FirePHP libraries, and accessible in all PHP files. What more do you want?

Related posts

Tags

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.