Firefox的Firephp插件是基于FireBug插件开发的一款调试工具.
他将你所要输出的信息通过header输出给客户端,并通过Firephp在FireBug的console和server中展示出来.
由于输出是在header中,所以不会影响任何页面代码.
可以用于Ajax调试及线上debug跟踪代码.
一、为你的firefox安装firephp
需要去firefox官方网站下载这个插件,请确定你已安装了firebug扩展
或者在你的Firefox菜单中点击tools->add-ons->get add-ons中搜索firephp
二、下载firephp代码并放在合适的目录
官方网站:http://www.firephp.org/
< < src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" type="text/javascript"> < src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" type="text/javascript"> ;p>三、代码演示
- 1. <?
- 2.
- 3. require ( 'FirePHPCore/fb.php' )
- 4.
- 5. /* NOTE: You must have Output Buffering enabled via
- 6. ob_start() or output_buffering ini directive. */
- 7.
- 8. fb('Hello World' ); /* Defaults to FirePHP::LOG */
- 9.
- 10. fb('Log message' ,FirePHP::LOG);
- 11. fb('Info message' ,FirePHP::INFO);
- 12. fb('Warn message' ,FirePHP::WARN);
- 13. fb('Error message' ,FirePHP::ERROR);
- 14.
- 15. fb('Message with label' , 'Label' ,FirePHP::LOG);
- 16.
- 17. fb(array ( 'key1' => 'val1' ,
- 18. 'key2' => array ( array ( 'v1' , 'v2' ), 'v3' )),
- 19. 'TestArray' ,FirePHP::LOG);
- 20.
- 21. function test( $Arg1 ) {
- 22. throw new Exception( 'Test Exception' );
- 23. }
- 24. try {
- 25. test(array ( 'Hello' => 'World' ));
- 26. } catch(Exception $e ) {
- 27. /* Log exception including stack trace & variables */
- 28. fb($e );
- 29. }
- 30.
- 31. fb(array ( '2 SQL queries took 0.06 seconds' , array (
- 32. array ( 'SQL Statement' , 'Time' , 'Result' ),
- 33. array ( 'SELECT * FROM Foo' , '0.02' , array ( 'row1' , 'row2' )),
- 34. array ( 'SELECT * FROM Bar' , '0.04' , array ( 'row1' , 'row2' ))
- 35. )),FirePHP::TABLE);
- 36.
- 37. /* Will show only in "Server" tab for the request */
- 38. fb(apache_request_headers(),'RequestHeaders' ,FirePHP::DUMP);
- 39.
- 40. ?>
显示结果如下:
几种类型显示方式:
FirePHP::LOG,FirePHP::INFO,FirePHP::WARN,FirePHP::ERROR
都会在console中显示出一行结果,只不过显示的图标不同页已.
fb函数:参数一为需要显示的任意值(string|array|integer…)
参数二如果不是类型时,则为这行的标签。例fb(’string’,'label’,FirePHP::LOG)
则在console中显示为 label:string
FirePHP::TABLE
会在console中显示出一个表格.
参数一的数组下标0的值为要显示的标题
参数一的数组下标1的值为要显示的行的信息
- fb ( array ( ' 2 SQL queries took 0.06 seconds ' , array (
- array ( ' SQL Statement ' , ' Time ' , ' Result ' ) ,
- array ( ' SELECT * FROM Foo ' , ' 0.02 ' , array ( ' row1 ' , ' row2 ' )) ,
- array ( ' SELECT * FROM Bar ' , ' 0.04 ' , array ( ' row1 ' , ' row2 ' ))
- )) , FirePHP :: TABLE ) ;
FirePHP::DUMP
会在NET标签下的此页面请求的Server标签下显示你要输出的信息。
原文地址:http://blog.csdn.net/leijuly/archive/2009/05/31/4227613.aspx