Saturday, November 27, 2010

DebugPanel - Web 2.0 way of print_r()

DebugPanel - Web 2.0 way of print_r()

Target Audience

Novice and intermediate PHP developers who are debugging the code by inserting

print_r($var); // or
var_dump($var); // or
var_export($var);

Note: those who are using DBG, Xdebug, Zend Debugger or others, please ignore this "lame" script - it will only make you laugh.

Purpose

Most of PHP developers start debugging by inserting something like this in their code and seeing results on the screen.

$var = call_some_obscure_function();
print '<pre>'.print_r($var, true).'</pre>';

DebugPanel also outputs the variable contents on the screen, but not directly at the place where it's called, but in a window floating over your script output with many convenience features.

Feature list

  • Collect all variable dumps in one place.
  • Highlight the syntax a little (different variable types get different background).
  • Save screen space by toggling visibility of different variables.
  • Handle multidimentional arrays with ease.
  • DebugPanel is displayed with position: absolute which is not interfering with the output of your script.
  • Drag and drop DebugPanel so it will not cover important information on your screen.
  • Never get warnings that you are trying to send HTTP headers or set cookies AFTER outputting debug information.
  • Handle objects as easy as multidimentional arrays.
  • Use the included PHP profiler to find the slowest code block in your script.
  • Use the included server statistics module to know what's going on with your server.
  • Remembers it's position after dragging, giving you pleasant debugging time!

Demo

If you haven't noticed - here it is, on the right of this page. Drag it and inspect it. Click on array titles to toggle visibility.

Usage

Step 1

Include the PHP class into your initialization (bootstraping) script.

require_once('class.DebugPanel.php');

It will automatically attach itself to the end of your script by using

register_shutdown_function()

and so render the DebugPanel in the browser.

Step 2

Call


dp('return value from strange function', $var);

every time you want to debug something.

Download

DebugPanel.zip
Somebody wants to host the file for me?

Todo

I don't have any plans yet. Please try DebugPanel and report bugs and suggestions.

Hint about Taylor Profiler

That's the way I use Taylor Profiler in my code (which takes care of the current class name and current function name in one go):

function some_slow_function() {
 if (isset($GLOBALS['profiler'])) $GLOBALS['profiler']->startTimer(__METHOD__);
 sleep(1);
 if (isset($GLOBALS['profiler'])) $GLOBALS['profiler']->stopTimer(__METHOD__);
}
DebugPanel
Request (array[7])
key typeName value
v1st string(16)8485AB8ACB4BBF90
MANTIS_VIEW_ALL_COOKIE string(2)50
_csoot string(13)1268814504774
_csuid string(16)48b417b23862dc80
MANTIS_STRING_COOKIE string(64)8bac76e935a27df7c99e72a7536cbfaae589e74d8380b7c59f407a5626c4508d
MANTIS_PROJECT_COOKIE string(1)6
livecid string(32)WI0om32G7446uxjqY4Kzg3Rs5LhQ8Fr2
System Variables (array[7])
key typeName value
REQUEST array[7]
REQUEST (array[7])
key typeName value
v1st string(16)8485AB8ACB4BBF90
MANTIS_VIEW_ALL_COOKIE string(2)50
_csoot string(13)1268814504774
_csuid string(16)48b417b23862dc80
MANTIS_STRING_COOKIE string(64)8bac76e935a27df7c99e72a7536cbfaae589e74d8380b7c59f407a5626c4508d
MANTIS_PROJECT_COOKIE string(1)6
livecid string(32)WI0om32G7446uxjqY4Kzg3Rs5LhQ8Fr2
GET array[0]
POST array[0]
FILES array[0]
COOKIE array[7]
COOKIE (array[7])
key typeName value
v1st string(16)8485AB8ACB4BBF90
MANTIS_VIEW_ALL_COOKIE string(2)50
_csoot string(13)1268814504774
_csuid string(16)48b417b23862dc80
MANTIS_STRING_COOKIE string(64)8bac76e935a27df7c99e72a7536cbfaae589e74d8380b7c59f407a5626c4508d
MANTIS_PROJECT_COOKIE string(1)6
livecid string(32)WI0om32G7446uxjqY4Kzg3Rs5LhQ8Fr2
SESSION NULL
GLOBALS NULL
Test (array[8])
key typeName value
string string(12)Hello World!
int integer(2)10
double double(6)3.1428
null NULL
bool boolean(1)1
array array[5]
array (array[5])
key typeName value
0 integer(1)0
1 integer(1)1
2 integer(1)2
3 integer(1)3
4 string(5)asd
panel array[1]
panel (array[1])
key typeName value
info array[1]
info (array[1])
key typeName value
position string(5)fixed
someHTML htmlString
someHTML (htmlString)
HiI am an HTML string.
TaylorProfiler (htmlString)
nr count time, ms percent routine
1 1x 1000.20 99.78% some_slow_function
2 0x 0.00 0.22% Missed
3 1x 0.03 0.00% unprofiled
Server Stat (htmlString)
PHP Info
Server localhost
PHP 5.2.8
Server time 16:27:50
memory_limit 262144.000 Kb
Mem. used 931.320 Kb
Mem. used % 0.355%
Mem. peak 931.781 Kb
Sess. size
Server Info
Disk space 20480.617 Mb
Disk used 13353.773 Mb
Disk used % 65.202%
CPU used % 5.736%
RAM 3955.957 Mb
RAM used 3215.152 Mb
RAM used % 81.274%
Uptime 82D 01:40:55
Server load 0.21

No comments: