Sunday, January 18, 2015

PHP Debugging tool/scripts(Like firebug for debugging javascript)

I used different tools for debugging or profiling PHP like xdebug,xhprof.

But I am looking for some tool(script) that can display PHP bebug log on the same page(Like firebug for javascript debugging).So that for debugging i not have to do echo,print_r in between of page.All those variables output come separately i can view them etc.

In that attempt i come across different tool like

1)Kint
http://raveren.github.io/kint/

2)PHP Debugbar
http://phpdebugbar.com/

3)PHP Debug
http://www.php-debug.com/www/

and there is more debug tool available for this.

I tried these three

1)Kint.

Overview:Simplest to integrate.
How to Use:It is simplest one to integrate.Just needed to include one php file.Then you can use dump/d/dd function to dump any variable.That variable will be displayed on the page

2)PHP Debug Bar

Overview:A bit more complicated(More steps) then Kint in terms of intallation etc.
It has more feature then kint.Like it has different tabs for different things(Can customized them also.)

Preparation before use

Download it from github.

Get the composer.phar file

#wget "https://getcomposer.org/composer.phar"

Run following command

#php composer.phar install

It will create vendor folder inside that directory

How to Use

Use following lines at the start of code

require <folder where debug bar unzipped>/vendor/autoload.php';

use DebugBar\StandardDebugBar;

(setBaseUrl needed if you unzipped debugbar other then root dir)

$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer()
                ->setBaseUrl('<Debug bar unzipped folder>/src/DebugBar/Resources');


$debugbar["messages"]->addMessage("hello world!");


In the head section needed to add this line.

<?php echo $debugbarRenderer->renderHead(); ?>

At the end of body needed to add this

<?php echo $debugbarRenderer->render() ?>

3)PHP-Debug

Overview:It is complicated one in comparison of previous two because of no of different features.But as per my use it is more useful.

Preperation before use

Download it from github.

How to Use

For ref

http://www.php-debug.com/www/install.php

I integrate it like this.

In the starting needed to add this section

$options = array(
    'HTML_DIV_images_path' => '<PHP Debug image folder url >',
    'HTML_DIV_css_path' => '<PHP Debug css folder location>',
    'HTML_DIV_js_path' =>  '<PHP Debug js folder location>',
);

// Additional ini path for PEAR
define('ADD_PEAR_ROOT', '<PHP Debug directory>');
set_include_path(ADD_PEAR_ROOT . PATH_SEPARATOR. get_include_path());

require_once '<PHP debug directory>/PHP/Debug.php';

// Debug object
$Dbg = new PHP_Debug($options);


Needed to add following lines in the head section

    <script type="text/javascript" src="<?php echo $options['HTML_DIV_js_path']; ?>/html_div.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="<?php echo $options['HTML_DIV_css_path']; ?>/html_div.css" />

At the end of body section needed following line

$Dbg->display();


PHP Debug output looks like this




1 comment:

clod said...

I like to use PHP debugger of Codelobster IDE