FirePHP application instance + comment

Source: Internet
Author: User
FirePHP use instance + comment 1. what is firePHP? firePHP is a ff plug-in for outputting php debugging information to the firebug console. II. what does firePHP do after it is officially released without affecting the page display? Debug php and output the debugging information to console 3. firePHP installation 1. Prerequisites: you need to install FirePHP instance + annotation
I. What is firePHP?

FirePHP is a ff plug-in that outputs php debugging information to the firebug console.

II. what is the use of firePHP?

After the official release, Debug php and output the debugging information to the console without affecting the page display.



3. install firePHP

1. Prerequisites: you need to install the ff plug-in-firebug.
2. Installation:
A. install the FirePHPCore component on the server
B. put the package under the Project Directory (assuming that firePHPCore is placed under the Project root directory)
C. server usage (import package)
D. enable the client
Enable the Firebug console, script, and network.
Add the current website to the FirePHP site

3. use
Add Php code to favorites

1. require ('firephpcore/fb. php'); // import the package
2.
3./* NOTE: You must have Output Buffering enabled
4. ob_start () or output_buffering ini directive .*/
5 ./*
6. enable the output buffer (because Firephp mainly uses the header function), there are three methods:
7. * add ob_start () to the front of the program ()
8. * modify php. ini to set output_buffering to 1 or on
9. * modify apache settings and add php_flag output_buffering on to the configuration file.
10 .*/
11.
12. ob_start ();
13.
14 ./*
15. start debugging: you can debug and output the following data types:
16. * string, which can be divided into four types: LOG, INFO, WARN, and ERROR
17. a row of results will be displayed on the console, except that different icons are displayed on different pages.
18. * Object or Array
19. * query the returned data through SQL
20. * thrown exception information
21. * information returned by the server (not output in the console, but in NET)
22 .*/
23.
24. fb ('Hello World');/* Defaults to FirePHP: LOG */
25.
26. fb ('log message', FirePHP: Log); // = fb ('log message', 'log'); = fb ('log message ');
27. fb ('info message', FirePHP: Info); // = fb ('info message', 'info ');
28. fb ('warn', FirePHP: Warn); // = fb ('warn', 'warn ');
29. fb ('error message', FirePHP: Error); // = fb ('error message', 'error ');
30.
31 ./*
32. fb function: parameter 1 is any value to be displayed (string | array | integer ...)
33. if parameter 2 is not a type, it is the label of this line. For example, fb ('string', 'label', FirePHP: LOG)
34. label: string is displayed on the console.
35 .*/
36. fb ('message with label', 'label', FirePHP: LOG );
37.
38. fb (array ('key1' => 'val1 ',
39. 'key2' => array ('v1 ', 'V2'), 'v3 ')),
40. 'testarray', FirePHP: LOG );
41.
42.
43.
44. function test ($ Arg1 ){
45. throw new Exception ('test exception ');
46 .}
47. try {
48. test (array ('Hello' => 'world '));
49.} catch (Exception $ e ){
50./* Log exception including stack trace & variables */
51. fb ($ e );
52 .}
53 ./*
54. FirePHP: TABLE
55. a table is displayed on the console.
56. The value of array subscript 0 of parameter 1 is the title to be displayed.
57. The value of array subscript 1 of parameter 1 is the information of the row to be displayed.
58 .*/
59. fb (array ('2 SQL queries took 0.06 seconds ', array (
60. array ('SQL Statement', 'time', 'result '),
61. array ('select * FROM Foo', '0. 02', array ('row1', 'row2 ')),
62. array ('select * FROM bar', '0. 04 ', array ('row1', 'row2 '))
63.), FirePHP: TABLE );
64.
65 ./*
66. FirePHP: DUMP
67. The information you want to output will be displayed under the Server tag requested on this page under the NET tag.
68 .*/
69./* Will show only in "Server" tab for the request */
70. fb (apache_request_headers (), 'requestheaders', FirePHP: DUMP );
71.
72. print 'Hello World ';

Require ('firephpcore/fb. php'); // import the package

/* NOTE: You must have Output Buffering enabled
Ob_start () or output_buffering ini directive .*/
/*
Open the output buffer (because Firephp mainly uses the header function), there are three methods:
* Add ob_start () to the front of the program ()
* Modify php. ini to set output_buffering to 1 or on
* Modify apache settings and add php_flag output_buffering on to the configuration file.
*/

Ob_start ();

/*
Start Debugging: you can debug and output the following data types:
* String, which can be divided into four types: LOG, INFO, WARN, and ERROR
A row of results will be displayed in the console, except that different icons are displayed on different pages.
* Object or Array
* Query the returned data through SQL
* Thrown exception information
* Information returned by the server (not output in the console, but in NET)
*/

Fb ('Hello World');/* Defaults to FirePHP: LOG */

Fb ('log message', FirePHP: Log); // = fb ('log message', 'log'); = fb ('log message ');
Fb ('info message', FirePHP: Info); // = fb ('info message', 'info ');
Fb ('warn', FirePHP: Warn); // = fb ('warn', 'warn ');
Fb ('error message', FirePHP: Error); // = fb ('error message', 'error ');

/*
Fb function: parameter 1: any value to be displayed (string | array | integer ...)
If parameter 2 is not a type, it is the label of this line. For example, fb ('string', 'label', FirePHP: LOG)
Label: string is displayed on the console.
*/
Fb ('message with label', 'label', FirePHP: LOG );

Fb (array ('key1' => 'val1 ',
'Key2' => array ('v1 ', 'V2'), 'v3 ')),
'Testarray', FirePHP: LOG );



Function test ($ Arg1 ){
Throw new Exception ('test exception ');
}
Try {
Test (array ('Hello' => 'world '));
} Catch (Exception $ e ){
/* Log exception including stack trace & variables */
Fb ($ e );
}
/*
FirePHP: TABLE
A table is displayed on the console.
The value of array subscript 0 of parameter 1 is the title to be displayed.
The value of array subscript 1 of parameter 1 is the information of the row to be displayed.
*/
Fb (array ('2 SQL queries took 0.06 seconds ', array (
Array ('SQL Statement', 'time', 'result '),
Array ('select * FROM Foo', '0. 02', array ('row1', 'row2 ')),
Array ('select * FROM bar', '0. 04 ', array ('row1', 'row2 '))
), FirePHP: TABLE );

/*
FirePHP: DUMP
The information you want to output is displayed under the Server tag requested on this page under the NET tag.
*/
/* Will show only in "Server" tab for the request */
Fb (apache_request_headers (), 'requestheaders', FirePHP: DUMP );

Print 'Hello World ';




Note that for data security, FB: setEnabled (false) is required when the bug is officially released. debugging information will not be output to the console.

References: http://blog.csdn.net/john_shen_tiro1/archive/2009/04/14/4071212.aspx
Http://blog.csdn.net/leijuly/archive/2009/05/31/4227613.aspx

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.