yii-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
155 followers

The Yii Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.

It is a ported to PHP famous Django Debug Toolbar.

Currently, the following panels have been written and are working:

  • Server info
  • Request timer
  • A list of superglobals
  • Application settings
  • SQL queries including time to execute and param bindings
  • Logging output via Yii built-in logging

Requirements

  • JavaScript enabled browser
  • Yii 1.1.4 +

Installation

Download sources from GitHub download page.

Extract the yii-debug-toolbar from archive under protected/extensions

Usage and Configuration

For use yii-debug-toolbar need to specify new route in log component:

'log'=>array(
        'class'=>'CLogRouter',
        'routes'=>array(
            array(
                'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
                'ipFilters'=>array('127.0.0.1','192.168.1.215'),
            ),
        ),
    ),
  • Make sure your IP is listed in the ipFilters setting. If you are working locally this option not required.
  • Enable Profiling and ParamLogging for all used DB connections.

Resources

Working preview

Screenshot 1

Screenshot 2

Change Log

November 28, 2011

* Added Views Rendering panel. It allows to view information about rendering process (view names, render methods, context objects and properties)
* Miscellaneous fixes

September 21, 2011

* Added SQL syntax highlighting
* Added highlighting of potentially inefficient queries 
* Miscellaneous fixes and UI enhancements

Juny 27, 2011

* Fixed PHP Error: `$_SESSION` variable is not defined

Juny 21, 2011

* Enhanced SQL log panel;
* Added new tab to SQL debug info with SQL servers info for all used connections;
* Added Yii debug status indicator to application settings panel;

Juny 20, 2011

* Initial release;

Total 20 comments

#13299 report it
kuya1284 at 2013/05/21 08:52am
AJAX response

The way I've dealt with AJAX in the past was by designing the app/api such that I could GET or POST using a generic form. In some cases, I've also used Firebug, which has a tab for viewing a rendered response.

#13287 report it
jneto at 2013/05/20 11:31pm
Ajax update

Is it possible to get the log from the ajax requests ?

#13254 report it
Ujjwal Prajapati at 2013/05/18 05:14am
Illegal String Offset

@m00nk ,

Did you find the solution to it? I am also having the same illegal offset error. Let me know.

#11942 report it
Edgar Kuskov at 2013/02/14 09:32am
Log execution time not run time

Is it possible to show the function execution time? I eam END-START= time? Because there is only the START time.

#11488 report it
zwobbel at 2013/01/16 10:35am
Thanks a lot!

Great work!

#11360 report it
kuya1284 at 2013/01/09 04:16am
Gateways, Load Balancers, Etc.

Here's another FYI for people still having problems. If you are having trouble with the ipFilters not working for you, it could be because your client/machine's IP Address isn't being detected. Instead, your Gateway, Load Balancer, or Proxy's IP Address may be getting filtered. To test this, try checking the return value of var_dump($_SERVER['REMOTE_ADDR']) and if the IP Address does not match your machine's IP Address, then that could be your problem.

This extension is setup to retrieve your IP Address using Yii::app()->request-getUserHostAddress(), which is most of the time the same as $_SERVER['REMOTE_ADDR']. The return value of $_SERVER['REMOTE_ADDR'] won't necessarily be your machine's IP. There are two ways in which I would deal with this. Either refactor YiiDebugToolbarRoute::init() or extend CHttpRequest and define your own getUserHostAddress().

Within either of the aforementioned methods, you may retrieve your real IP by using apache_request_headers() and parsing the X-Forwarded-For header. For example, you may add something like this:

$headers = apache_request_headers(); 
 
$ip = $headers['X-Forwarded-For'];
if (empty($ip))
    $ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';

Please note that this may not always work. The apache_request_headers() function has always worked for me, and I have never ran into a situation (yet) where it hasn't.

Good luck.

#11299 report it
realtebo at 2013/01/04 07:11am
Working, and great, great, great !!!!

Thanks, all is working and this extensions is really a must have

#11285 report it
Webnet668 at 2013/01/03 11:30am
Enabling Profiling for SQL

Enable SQL logging in your configuration...

'db' => array( 
     'enableProfiling' => true,
     'enableParamLogging' => true
),

As a side note, this works GREAT with the yii-environment extension.

#11215 report it
realtebo at 2012/12/28 02:09am
Is it still working ?

Is this toolbar still working with 1.1.12 ?

I can't figure how to enable. I extracted into right directory, i configured like example, but ... nothing new showed on the page

#11143 report it
jurassic82 at 2012/12/19 12:59pm
yes!

thanx krowe ! that is working :)

#11139 report it
Skinner at 2012/12/19 10:17am
@jurrasic82

Try to download and use latest version from GitHub

#11138 report it
krowe at 2012/12/19 10:05am
Well...

@jurrasic82: I see now. Ok, this is coming back to me now. I had this problem for awhile myself and I fixed it by modifying YiiDebugToolbar::createPanels(). Here is the code which worked for me:

private function createPanels() { /**Create panels. @return YiiDebugToolbar */
        foreach($this->getPanels() as $id=> $config) {
            if(!is_object($config)) {
                if(is_array($config)) {
                    isset($config['class'])||$config['class']=$id;
                    if(isset($config['enabled'])&&false===$config['enabled']) {
                        unset($this->_panels[$id]);
                        continue;
                    } else if(isset($config['enabled'])&&true===$config['enabled']) {
                        unset($config['enabled']);
                    }
                }
                $panel=Yii::createComponent($config, $this);
                if(false===($panel instanceof YiiDebugToolbarPanelInterface)) {
                    throw new CException(Yii::t('yii-debug-toolbar',
                            'The %class% class must be compatible with YiiDebugToolbarPanelInterface', array(
                            '%class%'=>get_class($panel))));
                }
                $panel->init();
                $this->_panels[$id]=$panel;
            }
        }
        return $this;
    }

EDIT: The only difference is that we've wrapped a portion of the code in an if(is_array()) block.

#11136 report it
Skinner at 2012/12/19 09:43am
> jurassic82

Could you provide a configuration that you use for this widget?

#11135 report it
jurassic82 at 2012/12/19 09:32am
No

No krowe ... you misread the error

/home/yii/my/framework/YiiBase.php exists and I have not modified anything in the framework directory.

What that error is telling is that file in the line (423) try to do an include of a file that does not exists, in this case 0.php

That's because I sent the Stack Trace:

YiiDebugToolbar.php at line 127 is running this YiiDebugToolbar->createPanels() Because $config is array("class" => 0), tries to import a file called 0.php since the Yii autoload override tries to get that file.

It's not about Yii framework ... it's about the $config array... there's so problem there.

Anyone ?

#11131 report it
krowe at 2012/12/19 08:37am
Error fix

@jurassic82 This looks like a file not found error in your index.php file. The location: /home/yii/my/framework/YiiBase.php doesn't exist. This is probably because you have one too many ../ in the path. You'll need to edit the line that looks like this: $yii=dirname(FILE).'/../../Apps/Yii/yii.php'; to make a good path.

PS: This question is probably more suited to the forums than this wiki.

EDIT: Actually, upon looking at this closer I see that the file not being found is the YiiBase.php file. This file is included by yii.php and it's relative location shouldn't ever be changed. Did you modify your library files? If so I'd change them back.

#11129 report it
jurassic82 at 2012/12/19 04:35am
Can't install :(

I had to put those lines you posted for m00nk ... but however:

include(0.php): failed to open stream: No such file or directory /home/yii/my/framework/YiiBase.php(423)

Stack Trace

0

  • /home/yii/my/framework/YiiBase.php(423): YiiBase::autoload()

1

  • /home/yii/my/framework/YiiBase.php(298): YiiBase::autoload(0)

2

  • /home/yii/my/framework/YiiBase.php(198): YiiBase::import(0, true)

3

  • /home/yii/my/protected/extensions/yii-debug-toolbar/YiiDebugToolbar.php(199): YiiBase::createComponent(array("class" => 0), YiiDebugToolbar)

4

  • /home/yii/my/protected/extensions/yii-debug-toolbar/YiiDebugToolbar.php(127): YiiDebugToolbar->createPanels()

help please ! ;)

#11074 report it
krowe at 2012/12/14 09:01am
Yep

Yes I checked it and I have an HTML validation error which says I'm missing a /div.

#11069 report it
kuya1284 at 2012/12/13 09:55pm
Any JS errors

Did you check for JS errors? Are you using a debbuger like firebug?

#11065 report it
krowe at 2012/12/13 03:45pm
Handy Tool But It Breaks One of My Pages

I use this tool for development and usually everything is fine. I have a page which it doesn't like though and it has been quite difficult to figure out whats going on. I think it is because the extension is printing out one of my vars which has a /div string in it. I'm wondering if there is a way to disable this extension for only some pages. Another related question I have is that I wonder if it is possible to disable only certain panels. The best solution for me would be if it could do both but either one of those options would get me through this much easier. Thanks.

#10521 report it
kuya1284 at 2012/11/02 12:14am
Possible fix for 5.4+

@m00nk,

It's possible that $config isn't an array. What you can try is add the following before line 168 so the code looks like the following:

is_array($config) || $config = [];
isset($config['class']) || $config['class'] = $id;

I thought I remember reading that you can use short array syntax like in other languages in 5.4. If not, replace [] with array(). Good luck.

Leave a comment

Please to leave your comment.

Create extension