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.
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.
<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
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.