
Debugging PHP scripts is definitely not enough covered on the Internet. Therefore, many, very many are satisfied with print_r-kami. The obvious drawback of this method is that you cannot debug AJAX, SOAP services, image generators, and generally scripts that do not directly render HTML documents.
Javascript developers use Firebug for debugging. As I have always envied them. Lepot - dedicated console, net-monitor, debugger, and all this in your favorite browser.
')
So, I found such an extension Firebug -
FirePHP . It allows you to display information in the Firebug console directly from PHP. This is done in a fairly simple way:
require ('FirePHP.class.php');
$ firephp = FirePHP :: getInstance (true);
$ firephp -> fb ("hello world! i'm warning you!", FirePHP :: WARN);
In addition, arbitrary data structures and
exceptions can be passed to Firebug. In the latter case, we obtain not only the object of the exception itself, but also the
contents of the stack . Opportunities weight, read the
documentation .
The advantage of such debugging is that the
data is transmitted not in the body of the page, but in the headers . This means that, firstly, the page is not cluttered with all sorts of var_dumps, and secondly, you can easily debug AJAX calls.
To use FirePHP, you need to: connect a
single file to the project and turn on
output buffering . Just.
About buffering: in fact, FirePHP wants no one to write to the output stream before it. It is logical, because it sends headers. Since you probably already use buffering to send your own headers, this is not a problem. I mean, it is not necessary to use exactly
ob_start()
, as in the manual.
I do not advise cracking
fb()
calls directly into the code. Think about what will happen to them on the production server. It is more correct to embed FirePHP into the debugging system - for example, there
are already
extensions for the Zend Framework and Symfony .
And I integrated into my debugger. Fly away
crossposted