FirePHP

4,838
-1

Published on

Mike Creuzer's presentation from the July, 2009 meeting of the Suburban Chicago PHP & Web Development meetup

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,838
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

FirePHP

  1. 1. FirePHP An extension to FireBug  for  AJAX Development
  2. 2. What is FirePHP <ul><li>FirePHP enables you to log to your  FirebugConsole  using a simple PHP method call. </li></ul><ul><li>All data is sent via response headers and will not interfere with the content on your page. </li></ul><ul><li>FirePHP is ideally suited for AJAX development where clean JSON and XML responses are required. </li></ul><ul><li>http://www.firephp.org/ </li></ul>
  3. 3. FirePHP Requirements <ul><li>Firefox with the FireBug extension with the NET tab enabled </li></ul><ul><li>PHP 4 or PHP 5 </li></ul><ul><li>Output Buffering must be used. </li></ul>
  4. 4. Installing Fire PHP <ul><li>First, install Firebug. </li></ul><ul><li>Then install the FirePHP FireFox addon. </li></ul><ul><li>     https://addons.mozilla.org/en-US/firefox/addon/6149 </li></ul><ul><li>Download the PHP library </li></ul><ul><li>     http://www.firephp.org/HQ/Install.htm </li></ul><ul><li>Or using PEAR </li></ul><ul><li>pear channel-discover pear.firephp.org pear install firephp/FirePHPCore </li></ul>
  5. 5. Hello World <ul><li>require_once ( 'FirePHPCore/FirePHP.class.php' ) ; $firephp = FirePHP :: getInstance ( true ) ; ob_start(); $firephp -> info ( 'Hello World' ) ; ob_end_flush (); </li></ul>
  6. 7. The actual headers for the example     <ul><li>The data is passed back to the browser in the Headers. </li></ul>
  7. 8. The basic calls <ul><li>$firephp->log('Hello World'); </li></ul><ul><li>$firephp->info('Hello World'); </li></ul><ul><li>$firephp->warn('Hello World'); </li></ul><ul><li>$firephp->error('Hello World'); </li></ul>
  8. 9. Custom Error, Exception, & Assertion Handling <ul><li>You can cause PHP to log errors to FirePHP instead of the normal error log file easily. $firephp -> registerErrorHandler ( $throwErrorExceptions = true ) ; $firephp -> registerExceptionHandler () ; $firephp -> registerAssertionHandler ( $convertAssertionErrorsToExceptions = true , $throwAssertionExceptions = false ) ; try { throw new Exception ( 'Test Exception' ) ; } catch ( Exception $e ) { $firephp -> error ( $e ) ; // or FB:: } </li></ul>
  9. 10. Groups & Nested levels <ul><li>You can add grouping and nested levels of groups to your FirePHP output. </li></ul><ul><li>$firephp -> group ( 'Test Group' ) ; </li></ul><ul><li>$firephp -> log ( 'Hello World' ) ; $firephp -> groupEnd () ;   $firephp -> group ( 'Collapsed and Colored Group' , array ( 'Collapsed' => true , 'Color' => '#FF00FF' )) ; </li></ul>
  10. 11. Data Tables <ul><li>You can even display Data Tables using FirePHP. </li></ul><ul><li>$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 ) ; </li></ul>
  11. 12. Tracing <ul><li>You can manually call a trace. Normal calls also have a trace built into them when you hover over/click on the messages on the right side bar. </li></ul><ul><li>$firephp -> trace ( 'Trace Label' ) ; </li></ul>
  12. 13. Variable Dumping <ul><li>You can dump a variable to the NET tab. I personally prefer to put one into a grouped alert call so you don't have to go clicking after it in another tab. </li></ul><ul><li>$firephp -> dump ( 'REQUEST' , $_REQUEST ) ; </li></ul>
  13. 14. Security <ul><li>FirePHP CAN reveal important 'stuff' to any web browser with FirePHP installed. </li></ul><ul><li>Please take steps to insure your data and application security. </li></ul><ul><ul><li>Remove FirePHP from the live server </li></ul></ul><ul><ul><li>Restrict access to authorized users only </li></ul></ul><ul><ul><li>Restrict access to authorized IP addresses only </li></ul></ul><ul><li>require_once('FirePHPCore/FirePHP.class.php'); </li></ul><ul><li>require_once('FirePHPCore/fb.php'); </li></ul><ul><li>$firephp = FirePHP::getInstance(true); </li></ul><ul><li>if(in_array( $my->id, array('000', '001') ) ) // Hard Coded Joomla User ID's </li></ul><ul><li>{ </li></ul><ul><li>$firephp->setEnabled(true); </li></ul><ul><li>} else { </li></ul><ul><li>$firephp->setEnabled(false); </li></ul><ul><li>} </li></ul>
  14. 15. FirePHP isn't just for Debugging <ul><li>You can do more then just debug code with FirePHP. You can display anything that you want to keep hidden from normal users. </li></ul><ul><ul><li>Current logged in users </li></ul></ul><ul><ul><li>Last actions by users </li></ul></ul><ul><ul><li>Server Statistics </li></ul></ul><ul><ul><li>Code Profiling </li></ul></ul><ul><ul><li>Code Decision Tree logic choices </li></ul></ul><ul><ul><li>Additional information such as calculation intermediaries </li></ul></ul><ul><ul><li>Design notes about the page </li></ul></ul><ul><ul><li>TODO notes </li></ul></ul><ul><ul><li>Reminder to get the milk on the way home </li></ul></ul><ul><ul><li>Hire notices for anybody looking at the console on your site </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×