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 how many A's the current page has received, and other functions.
PHP also has a tool that is as useful as firebug, and that is FirePHP.
FirePHP is a plug-in attached to firebug, which is 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. On the browser side, use Firebug + FirePHP to receive and view the output debugging information. This debugging information will be directly attached to the returned HTTP header information. This information does not It will be displayed directly by the browser and will only be displayed in firephp, effectively achieving the problem of no conflict between debugging and page display. (Must use firefox browser)
FirePHP debugging principles
Through the server-side library FirePHPCore, and the Firebug-based plug-in FirePHP, PHP scripts can send debugging information to the browser through HTTP request headers. Once you set up FirePHP, you can get PHP script warnings and errors in Firebug's console, just like debugging JavaScript directly.
Installation
First, you need to install Firefox, Firebug, and FirePHP. It is recommended to use the latest versions of FireFox 19.0.2, Firebug 1.11.2, and FirePHP 0.7.1;
Secondly 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+, only use fb.php and 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: # Create a test directory in the unzipped directory for testing FirePHP
firephptest.php test
Next, create the test case firephptest.php in the test directory:
require_once '../lib/FirePHPCore/fb.php';
$firephp = FirePHP::getInstance(true);
$var = array(1, 2, 'hello world', array(1));
fb($var);
fb($var, 'Label'); Finally, visit www.domain.com/~zhanhailiang/FirePHPCore-0.3.2/test/firephptest.php in the browser, and 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'=> ... ) You can see the response header details of the HTTP request through the Firebug network panel:
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 By analyzing the FirePHP opening and closing options, we can find that X-Wf-*** does not exist in the response information when FirePHP is closed. It can be found by analyzing HTTP requests,
When FirePHP is turned off, 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 turned on, 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 You can see that the difference in HTTP request headers when FirePHP is turned on 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 FirePHP installed:
/**
* 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;
}So is the x-insight request header useful? Looking at all the code in FirePHPCore, I didn't see the use of x-insight, so I guess x-insight has no actual use. In order to verify my guess, I used the FF extended HTTPRequester tool to simulate constructing a UA:FirePHP without x-insight request header. 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