FirePHP debugging Guide

Source: Internet
Author: User

For Web Front-end debugging, Firebug is an indispensable debugging tool. It can monitor the network, monitor css and js errors, view DOM nodes, view the current page, and obtain several A functions.
PHP also has a tool that works with firebug, that is, FirePHP.
FirePHP is a plug-in attached to firebug. It is used to debug PHP and the operation process is very simple. Use the PHP log library provided by FirePHP on the PHP end to output debugging information, and use Firebug + FirePHP on the browser side to receive and view the output debugging information, the debugging information will be directly appended to the returned HTTP header information, which will not be directly displayed by the browser, but will only be displayed in firephp, this effectively prevents conflict between debugging and page display. (Firefox is required)
FirePHP debugging Principle
Through the server library FirePHPCore and FirePHP Based on Firebug, the PHP script can send debugging information to the browser through the HTTP request header. Once you enable FirePHP, you can get the PHP script warning and error in the Firebug console, just like directly debugging JavaScript.

Install
First, install Firefox, Firebug, and FirePHP. We recommend that you use the latest FireFox versions 19.0.2, Firebug 1.11.2, and FirePHP 0.7.1;

Next, download the 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 +, use only the fb. php, FirePHP. class. php 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: # create the test directory under the decompressed directory to test FirePHP.
Firephptest. php Test
Next, create the test case firephptest. php In the test directory:

<? 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, access www.domain.com/~ in the browser /~ 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 Firebug network panel shows the HTTP request response header details:

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 lightning -***. By analyzing HTTP requests, we can find that,

When FirePHP is disabled, 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 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 FirePHP is enabled, 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 be seen that the difference between the HTTP request header when FirePHP is enabled is:

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 viewing the FirePHP. class. php source code, you can see that FirePHPCore uses UA to determine whether the client has installed 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. 000000', '> = ')){
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. 000000', '> = ')){
Return true;
}
Return false;
} Is the x-insight Request Header used? View all the code in FirePHPCore, and do not see the use of x-insight, so I guess x-insight is not actually used. To verify my guesses, use the FF extension HTTPRequester tool to simulate the construction of a request header with only UA: FirePHP but not x-insight, test whether the response header is consistent with the response header containing the x-insight request:

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

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.