firephp Debugging Guide _php Tutorial

Source: Internet
Author: User
If the Web front-end debugging, Firebug is an indispensable debugging tool, it can monitor the network, monitoring CSS, JS errors, view the DOM node, view the current page to get a few a, and so on.
PHP also has a tool that works well with Firebug, which is firephp.
Firephp is a plug-in attached to the Firebug, used to debug PHP, the operation process is very simple. On the PHP side use the PHP logging class library provided by firephp to output debugging information, using Firebug + firephp on the browser side to receive debugging information of the view output, these debugging information is directly attached to the returned HTTP header information, this information will not be displayed directly by the browser, Only in the firephp to get the display, effectively achieve the debugging and page display is not conflicting issues. (must use Firefox browser)
firephp Debugging Principle
Through the server-side library Firephpcore, and Firebug-based plug-in firephp,php scripts can send debug messages to the browser via HTTP request hair. Once you set the firephp on, you can get PHP script warnings and errors in the Firebug console, just like debugging JavaScript directly.

Installation
First you need to install firefox,firebug,firephp, we recommend using the latest version of Firefox 19.0.2,firebug 1.11.2,firephp 0.7.1;

Next download server Side library 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: # for php5+ Just use it for fb.php,firephp.class.php these two files
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 : # Self-created test directory under Unzip directory for testing firephp
firephptest.php Test
Next, create a testing case in the tests directory firephptest.php:


Require_once '. /lib/firephpcore/fb.php ';

$firephp = Firephp::getinstance (true);

$var = Array (1, 2, ' Hello World ', Array (1));
FB ($var);
FB ($var, ' Label '); Finally, in the browser access www.domain.com/~zhanhailiang/FirePHPCore-0.3.2/test/firephptest.php, you can see the following output on the console:

http://itravel.smartcom.cc/~zhanhailiang/FirePHPCore-0.3.2/test/firephptest.php

Log:array (' 0 ' = ' 1 ', ' 1 ' = ' 2 ', ' 2 ' = ...)
Log:Label:array (' 0 ' = ' 1 ', ' 1 ' = ' 2 ', ' 2 ' = ...) The response header details of the HTTP request can be seen through the Firebug network panel:

Connection Close
Content-encoding gzip
Content-type text/html; Charset=utf-8
Date Fri, Mar 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 by analyzing the firephp open and close options, It can be found that there is no x-wf-*** in the response message when the firephp is closed. By analyzing HTTP requests, you can find

When the Firephp,http request header is closed:

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 when you turn on firephp, the HTTP request header is:

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 can see that the HTTP request header differs when firephp is turned on:

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 by looking at FirePHP.class.php source can see Firephpcore through the UA to determine whether the client installs firephp:

/**
* Check if firephp is installed on client
*
* @return Boolean
*/
Public Function Detectcliente XTension ()
{
//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;
} is the X-insight request header used? Looking at all the code in Firephpcore, and didn't see the purpose of x-insight, so I guess X-insight has no practical use. To verify my guess, using the FF extension Httprequester tool to simulate the construction of a ua:firephp, without x-insight the request header, the test whether the response header and the response header containing the x-insight request are consistent:

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--
OK
Server:nginx
Date:fri, 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/477612.html techarticle if the Web front-end debugging, Firebug is an indispensable debugging tool, it can monitor the network, monitoring CSS, JS errors, view the DOM node, view the current page to get a few a, and so on ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.