How to use Firebug to Debug PHP Scripts
We usually use Firebug to debug Javascript, AJAX and so on, so here is how to use Firebug to debug your PHP scripts. I have written long time ago a PHP class Buggy to help me store debug information in database so it could be better analyzed later. Now that many are using Firebug, I find it pretty interesting to have such debug information available directly in Firebug so you can group both server-side and client-side debug info in a single place.
Last week I saw FirePHP, which introduce a specific protocol to help debugging PHP scripts and add a new tab to FireBug to visualize results. Here is a fast way to create your own debug solution and use Firebug itself to visualize these informations.
The solution is in reality inspired from FirePHP and my old Buggy PHP class, but more simplified to track time consumption in your code :
Usage of the class is simply by setting different $module names to every part that you would like to track. Let say :
And in Firebug you have this message in console :
I simply altered the page with some JavaScript, and from PHP you can enable disable debugging message. Now we can add more advanced features for example we can track PHP errors inside Firebug and here is a more complete example :
And below a screenshot of how results looks like in Firebug :
You can also have a look on the link I have provided in the beginning and see how to include SQL queries. Saving debug data in database is very long story that I didn't wanted to talk about here but this will give you lots of ideas to improve your application, you can for example retrieve debug info via AJAX and visualize graphics... etc. Let me know if you have any comment or suggestion.


Subscribe to AJAX Magazine's feed