【转载】让咱们来FirePHP

原文地址:http://www.phpchina.com/index.php?action-viewthread-tid-105221php

FirePHP是什么?
FirePHP是一个利用Firebug console栏输出调试信息方便程序调试。
这一切只须要调用几个简单的函数。

他看起来是怎么个样子?html

 
  
1 <? php
2
3 FB :: log ( ' Log message ' );
4 FB :: info( ' Info message ' );
5 FB :: warn( ' Warn message ' );
6 FB :: error( ' Error message ' );
7
8   ?>

2011040211510872.png
为何要用它?
在开发环境下正常运行的程序放在生产环境出问题了!
我指望能够在生产环境中进行修改。但不指望客户看到这一切的发生。
请选择FirePHP。
常规的PHPUnit确实能帮助你们进行自动化测试。但我指望更为直观的结果显示。
让我知道程序内发生了什么。看到结果按约输出内心才放心。
请选择FirePHP。
常规var_export()显示在页面上,破坏了页面结构,影响了界面开发人员的工做。
请选择FirePHP。
更多好处等待您的发现。

开始咱们的FirePHP之旅:

一、确认您安装了FireFox(对FF有持有偏见,抵制FF的能够走了)。
FireFox:http://www.mozillaonline.com/
二、确认您安装了Firebug。
Firebug:https://addons.mozilla.org/zh-CN/firefox/addon/1843
三、安装FirePHP插件。
FirePHP:https://addons.mozilla.org/zh-CN/firefox/addon/6149
四、安装FirePHP服务器端。
这里有两种安装方式一种经过pear安装,另外一种直接下载代码包。
这里建议使用第二种方式。
方式一 经过pear安装:
pear安装方式请参见 Netbeans新增PHPUnit支持 试用手记 http://bbs.phpchina.com/thread-104215-1-1.html
如下为FirePHP安装所需命令。服务器

 
  
1 pear channel - discover pear . firephp . org
2 pear install firephp / FirePHPCore


方式二 直接下载代码包:
下载地址: http://www.firephp.org/DownloadR ... y-FirePHPCore-0.2.1
五、服务端使用方式。
  a、引入代码网络

 
  
1 require_once ( ' FirePHPCore/fb.php ' ); // 建议引入此文件便可。文件目录自行安排。使用pear方式安装也是这样引入。


b、开启客户端
  开启Firebug 控制台、脚本、网络。
  将当前网站添加入FirePHP容许站点(十分容易本身熟悉一下就知道了)。
b、常规使用函数

 
  
1 <? php
2 include_once ( ' FirePHP/fb.php ' );
3 FB :: log ( ' Hello World ! ' );  // 常规记录
4 FB :: group( ' Test Group A ' ); // 记录分组
5 // 如下为按照不一样类别或者类型进行信息记录
6 FB :: log ( ' Plain Message ' );
7 FB :: info( ' Info Message ' );
8 FB :: warn( ' Warn Message ' );
9 FB :: error( ' Error Message ' );
10
11 FB :: log ( ' Message ' , ' Optional Label ' );
12 FB :: groupEnd();
13 FB :: group( ' Test Group B ' );
14 FB :: log ( ' Hello World B ' );
15 FB :: log ( ' Plain Message ' );
16 FB :: info( ' Info Message ' );
17 FB :: warn( ' Warn Message ' );
18 FB :: error( ' Error Message ' );
19
20 FB :: log ( ' Message ' , ' Optional Label ' );
21 FB :: groupEnd();
22
23 // 将信息做为table输出
24 $table [] = array ( ' Col 1 Heading ' , ' Col 2 Heading ' , ' Col 2 Heading ' );
25 $table [] = array ( ' Row 1 Col 1 ' , ' Row 1 Col 2 ' , ' Row 1 Col 2 ' );
26 $table [] = array ( ' Row 2 Col 1 ' , ' Row 2 Col 2 ' );
27 $table [] = array ( ' Row 3 Col 1 ' , ' Row 3 Col 2 ' );
28
29 FB :: table( ' Table Label ' , $table );
30
31 // 在异常处理中使用FirePHP
32 class MyException extends Exception {
33 public function __construct( $message , $code ) {
34 parent :: __construct( $message , $code );
35 }
36 public function log (){
37 FB :: log ( $this -> getMessage());
38 }
39 }
40
41 try {
42 echo ' MoXie ' ;
43 throw new MyException( ' some description ' , 1 );
44 } catch (MyException $e ){
45 $e -> log ();
46 }
47
48 ?>



参考资料:http://www.firephp.org/HQ/Use.htmpost

原文地址:http://www.phpchina.com/index.php?action-viewthread-tid-105221测试

转载于:https://www.cnblogs.com/ainiaa/archive/2011/04/02/2003031.html网站