Home > Backend Development > PHP Tutorial > How to use the FireFox plug-in FirePHP to debug PHP_PHP tutorial

How to use the FireFox plug-in FirePHP to debug PHP_PHP tutorial

WBOY
Release: 2016-07-21 14:59:48
Original
1017 people have browsed it

If you are like me, you will be completely unable to leave FireBug when developing web projects. This little "bug" is an amazing and useful HTML/CSS/JavaScript/Ajax debugger. But you may not know that this can also be used to debug PHP. Yes, it can, thanks to a FireFox plug-in called FirePHP.

With a small server-side library and this plug-in for Firebug, your PHP scripts can send debugging information to the browser, easily encoded through HTTP response headers. Once you're set up, you can get PHP script warnings and errors in Fiirebug's console, which feels like debugging JavaScript directly

To use this tool, you first need to install the FirePHP plug-in. This plugin requires you to have FireBug installed. After installing FirePHP, when you reopen the Firebug panel, you will see a new blue bug icon added. Clicking this icon will bring up a menu to turn FirePHP on or off.

FirePHP Menu

Of course, we can’t do anything at this time, you still need to install the FirePHP server. This is a standalone version that you can download manually or use PEAR. After installation, you can easily add this library to your code. It has been designed in many versions to integrate into multiple frameworks or management systems, such as WP-FirePHP plugin for WordPress and JFirePHP plugin for Joomla. Ignoring these for now, we'll focus on standalone features.

Once you have deployed the FirePHP library on your server, you also need to add the following code to your code:
<span style="FONT-FAMILY: NSimsun; COLOR: #ff0000"> require_once('FirePHPCore/fb.php');<code><span style="FONT-FAMILY: NSimsun; COLOR: #ff0000">require_once('FirePHPCore/fb.php');<br></span>
<span style="FONT-FAMILY: NSimsun">ob_start</span>This is because FirePHP sends logged data via HTTP headers, and you need to cache the output produced by your code in response to the headers Information is obtained from here about what the code generates. This can be achieved by <br>ob_start<br> at the head of the code. <span style="FONT-FAMILY: NSimsun; COLOR: #ff0000">ob_start();<br></span><span style="FONT-FAMILY: NSimsun">fb</span><span style="FONT-FAMILY: NSimsun; COLOR: #ff0000">ob_start();<br><div class="codetitle">When these steps are completed, you can start using FirePHP. All you need to do is call the <code><span style="CURSOR: pointer" onclick="doCopy('code14707')">fb<u></u></span> function wherever you want to log. You can also use an optional label and constant to define a predefined message, an error, a warning, or a message.

Copy code

The code is as follows:


$var = array('a'=>'pizza', 'b' =>'cookies', 'c'=>'celery');
fb($var);
fb($var, "An array");
fb($var, FirePHP ::WARN);
fb($var, FirePHP::INFO);

fb($var, 'An array with an Error type', FirePHP::ERROR);

FirePHP Console Output

These codes will output in Firebug console as shown below

<span style="FONT-FAMILY: NSimsun">FirePHP::TRACE常量,你可以在</span>fb被调用的地方查看 行数、类名和方法名<br>You can also use FirePHP to track the execution of your program: by using the FirePHP::TRACE constant, you can do this in the

line Number, class name and method name

Copy code

The code is as follows:


function hello() {
fb('Hello World!', FirePHP::TRACE);
}
function greet() { hello(); } greet();
The output produced is as follows

FirePHP Trace Output

This tracking function can be perfect for debugging more complex code, allowing you to know exactly where your method is called.
Of course, don’t forget that you need to remove your debugging statements before your code is released.
There is a lot of FirePHP content that has not been covered here. I'm just going to briefly show you FirePHP's API, and there are many advanced object-oriented APIs.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328107.htmlTechArticleIf you are like me, you will be completely unable to leave FireBug when developing web projects. This little "bug" is an amazing and useful HTML/CSS/JavaScript/Ajax debugger. But you...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template