您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 通辽分类信息网,免费分类信息发布

FirePHP调试指南_PHP教程

2024/2/27 14:51:35发布18次查看
如果web前端调试来说,firebug是不可或缺好的调试工具,它能够监控网络、监测css、js错误,查看dom节点,查看当前页面获得了几个a,等等功能。
php同样也有配合firebug这么好用的工具,那就是firephp。
firephp是一个附加在 firebug 上面的插件,用来调试php,操作过程很简单。在php端使用firephp提供的php日志记录类库来输出调试信息, 在浏览器端使用 firebug + firephp 来接收查看输出的调试信息,这些调试信息会直接附加在返回的http头信息里,这些信息不会被浏览器直接显示,只会在firephp 获取显示,有效的达到了调试和页面显示都不冲突的问题。(必须使用firefox浏览器)
firephp调试原理
通过服务端库firephpcore,和基于firebug的插件firephp,php脚本可以通过http请求头发送调试信息到浏览器。一旦你设置开启firephp,你可以在firebug的控制台获得php脚本警告和错误,就感觉像直接调试javascript一样。
安装
首先需要安装firefox,firebug,firephp,建议使用最新版本firefox 19.0.2,firebug 1.11.2,firephp 0.7.1;
其次下载服务器端库firephpcore:
> wget http://www.firephp.org/downloadrelease/firephplibrary-firephpcore-0.3.2
> file firephplibrary-firephpcore-0.3.2
firephplibrary-firephpcore-0.3.2: zip archive data, at least v2.0 to extract
> unzip firephplibrary-firephpcore-0.3.2
~/public_html/firephpcore-0.3.2> ls -r
.:
changelog  credits  firephpcore-0.3.2  firephplibrary-firephpcore-0.3.2  lib  readme  test
./firephpcore-0.3.2:
changelog  credits  lib  readme
./firephpcore-0.3.2/lib:
firephpcore
./firephpcore-0.3.2/lib/firephpcore: # 对于php5+只需用于fb.php,firephp.class.php这两个文件
fb.php  fb.php4  firephp.class.php  firephp.class.php4  license
./lib:
firephpcore
./lib/firephpcore:
fb.php  fb.php4  firephp.class.php  firephp.class.php4  license
./test: # 自已在解压缩目录下创建test目录用于测试firephp
firephptest.php测试
接下来 在test目录下创建测试用例firephptest.php:
'1', '1'=>'2', '2'=> ... )
log: label: array('0'=>'1', '1'=>'2', '2'=> ... )通过firebug网络面板可以看到http请求的响应头详情:
connection  close
content-encoding    gzip
content-type    text/html; charset=utf-8
date    fri, 29 mar 2013 01:39:32 gmt
server  nginx
transfer-encoding   chunked
x-wf-1-1-1-1    142|[{type:log,file:\/home\/zhanhailiang\/public_html\/firephpcore-0.3.2\/test\/firephptest.php,line:8},[1,2,hello world,[1]]]|
x-wf-1-1-1-2    158|[{type:log,label:label,file:\/home\/zhanhailiang\/public_html\/firephpcore-0.3.2\/test\/firephptest.php,line:9},[1,2,hello world,[1]]]|
x-wf-1-index    2
x-wf-1-plugin-1 http://meta.firephp.org/wildfire/plugin/firephp/library-firephpcore/0.3
x-wf-1-structure-1  http://meta.firephp.org/wildfire/structure/firephp/firebugconsole/0.1
x-wf-protocol-1 http://meta.wildfirehq.org/protocol/jsonstream/0.2通过分析firephp开启和关闭选项,可以发现当firephp关闭时响应信息里是不存在x-wf-***。通过分析http请求可以发现,
当关闭firephp,http请求头为:
accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
accept-encoding gzip, deflate
accept-language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
cache-control   max-age=0
connection  keep-alive
host    itravel.smartcom.cc
user-agent  mozilla/5.0 (windows nt 6.1; rv:19.0) gecko/20100101 firefox/19.0当开启firephp时,http请求头为:
accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
accept-encoding gzip, deflate
accept-language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
cache-control   no-cache
connection  keep-alive
host    itravel.smartcom.cc
pragma  no-cache
user-agent  mozilla/5.0 (windows nt 6.1; rv:19.0) gecko/20100101 firefox/19.0 firephp/0.7.1
x-insight   activate可以看出开启firephp时http请求头区别在于:
pragma  no-cache
user-agent  mozilla/5.0 (windows nt 6.1; rv:19.0) gecko/20100101 firefox/19.0 firephp/0.7.1
x-insight   activate通过查看firephp.class.php源码可以看到firephpcore通过ua来判断客户端是否安装firephp:
    /**
     * check if firephp is installed on client
     *
     * @return boolean
     */
    public function detectclientextension()
    {
        // check if firephp is installed on client via user-agent header
        if (@preg_match_all('/\sfirephp\/([\.\d]*)\s?/si',$this->getuseragent(),$m) &&
           version_compare($m[1][0],'0.0.6','>=')) {
            return true;
        } else
        // check if firephp is installed on client via x-firephp-version header
        if (@preg_match_all('/^([\.\d]*)$/si',$this->getrequestheader(x-firephp-version),$m) &&
           version_compare($m[1][0],'0.0.6','>=')) {
            return true;
        }
        return false;
    }那么x-insight请求头有没有用呢?查看firephpcore里的所有代码,并没有看到x-insight的用途,所以我猜测x-insight并没有实际用途。为了验证我的猜测,使用ff扩展httprequester工具模拟构造一个只有ua:firephp,而没有x-insight请求头,测试下是否响应头和包含x-insight请求的响应头是否一致:
get http://itravel.smartcom.cc/~zhanhailiang/firephpcore-0.3.2/test/firephptest.php
user-agent: mozilla/5.0 (windows nt 6.1; rv:19.0) gecko/20100101 firefox/19.0 firephp/0.7.1
 -- response --
200 ok
server:  nginx
date:  fri, 29 mar 2013 02:34:54 gmt
content-type:  text/html; charset=utf-8
transfer-encoding:  chunked
connection:  close
x-wf-1-1-1-1:  142|[{type:log,file:\/home\/zhanhailiang\/public_html\/firephpcore-0.3.2\/test\/firephptest.php,line:8},[1,2,hello world,[1]]]|
x-wf-protocol-1:  http://meta.wildfirehq.org/protocol/jsonstream/0.2
x-wf-1-plugin-1:  http://meta.firephp.org/wildfire/plugin/firephp/library-firephpcore/0.3
x-wf-1-structure-1:  http://meta.firephp.org/wildfire/structure/firephp/firebugconsole/0.1
x-wf-1-1-1-2:  158|[{type:log,label:label,file:\/home\/zhanhailiang\/public_html\/firephpcore-0.3.2\/test\/firephptest.php,line:9},[1,2,hello world,[1]]]|
x-wf-1-index:  2
content-encoding:  gzip
http://www.bkjia.com/phpjc/477612.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/477612.htmltecharticle如果web前端调试来说,firebug是不可或缺好的调试工具,它能够监控网络、监测css、js错误,查看dom节点,查看当前页面获得了几个a,等等功...
通辽分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录