42 function array_contents(&$array, $max_depth=0, $ignore_ints=FALSE, $depth=0)
44 $string = $indent =
'';
45 for ($i = 0; $i < $depth; $i++) {
48 if (!empty($max_depth) && $depth >= $max_depth) {
49 return $indent.
"[Max Depth Reached]\n";
51 if (count($array) == 0)
return $indent.
"[Empty]\n";
53 while (list($key,$value) = each($array)) {
54 $print_key = str_replace(
"\n",
"\\n",str_replace(
"\r",
"\\r",str_replace(
"\t",
"\\t",addslashes($key))));
55 if ($ignore_ints && gettype($key) ==
'integer') {
58 $type = gettype($value);
59 if ($type ==
'array' || $type ==
'object') {
61 .((is_string($key)) ?
"\"$print_key\"": $key).
' => '
62 .(($type ==
'array') ?
"array (\n" :
'')
63 .(($type ==
'object') ?
'new '.get_class($value).
" Object (\n" :
'');
64 $string .= array_contents($value, $max_depth, $ignore_ints, $depth + 1);
65 $string .= $indent.
"),\n";
67 if (is_string($value)) {
68 $value = str_replace(
"\n",
"\\n",str_replace(
"\r",
"\\r",str_replace(
"\t",
"\\t",addslashes($value))));
71 .((is_string($key)) ?
"\"$print_key\"" : $key).
' => '
72 .((is_string($value)) ?
"\"$value\"" : $value).
",\n";
75 $string[ strlen($string) - 2 ] =
' ';
88 function ascii_chart()
90 for ($i=0; $i<256; $i++) {
91 echo(($i==0) ?
'<table><tr>' :
'').
"<td>$i:</td><td>".chr($i).
'</td><td> </td>'.((7==($i%8)) ?
'</tr><tr>' :
'').(($i==255) ?
'</tr></table>' :
'');
104 function inject_beef()
107 list($msec, $sec) = explode(
' ',microtime());
108 $BAM = ((double) $sec) + ((double) $msec);
110 global $SPEED_CHECK_LAST_HIT, $SPEED_CHECK_TOTAL;
111 if ($SPEED_CHECK_LAST_HIT) {
112 $elapsed = $BAM - $SPEED_CHECK_LAST_HIT;
113 $SPEED_CHECK_TOTAL += $elapsed;
114 $check = sprintf(
'%.5f / %.5f',$elapsed,$SPEED_CHECK_TOTAL);
117 list($msec, $sec) = explode(
' ',microtime());
119 $SPEED_CHECK_LAST_HIT = ((double) $sec) + ((double) $msec);
121 $len = strlen($check);
127 .--, '.str_repeat(
' ',$len).
' ,--.
128 l_/ \ _'.str_repeat(
'_',$len).
'_ / \_J
129 \ `-./__'.str_repeat(
'_',$len).
'__\.-\' /
130 `..---'.str_repeat(
'-',$len).
'----..\'
131 `-/ '.str_repeat(
' ',$len).
' \'
133 `.__'.str_repeat(
'_',$len).
'___.\'
152 function bam($x=
'BAM!', $max_depth=0, $style=
'')
154 pre_echo($x, $max_depth, $style);
174 function minibam($contents, $title=
'BAM', $max_depth=0, $auto_expand=FALSE)
176 if (defined(
'SQ_DEBUG_HIDE_MINIBAM') && SQ_DEBUG_HIDE_MINIBAM) {
180 if (php_sapi_name() ==
'cli') {
182 echo
"\n------------------------------------\n";
184 pre_echo($contents, $max_depth);
188 $id = rawurlencode(strtolower($title)).
'_'.microtime();
190 <table border=
"1" cellspacing=
"0" cellpadding=
"2" style=
"background-color: #FFDDDD; color: #000000;">
192 <td style=
"cursor: pointer; cursor: hand; text-decoration: underline; font-weight: bold" onclick=
"elt = document.getElementById('<?php echo $id; ?>'); elt.style.display = (elt.style.display == 'none') ? '' : 'none';"><?php echo $title; ?></a></td>
195 <td
id=
"<?php echo $id; ?>" style=
"display: <?php echo ($auto_expand ? '' : 'none'); ?>">
196 <?php pre_echo($contents, $max_depth); ?>
217 function pre_echo($x, $max_depth=0, $style=
'')
219 if (php_sapi_name() ==
'cli') {
220 echo
"\n------------------------------------\n";
222 echo
"\n",
'<div align="left"><pre style="', $style,
'font-family: courier, monospace;">';
226 if ($type ==
'object' && !$max_depth) {
229 if ($type ==
'object' || $type ==
'array') {
231 if (!$max_depth) $max_depth = 10;
232 $x = array_contents($x, $max_depth);
234 $x = str_replace(
"\t",
' ', $x);
236 echo (php_sapi_name() ==
'cli') ? $x : htmlspecialchars($x);
239 if (php_sapi_name() ==
'cli') {
240 echo
"\n------------------------------------\n";
242 echo
'</pre></div>',
"\n";
258 function speed_check($str=
'', $html=TRUE, $log_error=TRUE, $log_file =
'')
260 list($msec, $sec) = explode(
' ',microtime());
262 $BAM = ((double) $sec) + ((double) $msec);
264 global $SPEED_CHECK_LAST_HIT, $SPEED_CHECK_TOTAL;
265 if ($SPEED_CHECK_LAST_HIT) {
266 $elapsed = $BAM - $SPEED_CHECK_LAST_HIT;
267 $SPEED_CHECK_TOTAL += $elapsed;
269 echo(
'<table cellpadding=0 cellspacing=0 border=0 bgcolor="#ffff88"><tr><td><p style="color:red;font-weight:bold;font-family:sans-serif;font-size:13px;">'.sprintf(
'%.5f / %.5f',$elapsed,$SPEED_CHECK_TOTAL).
" $str</p></td></tr></table>");
272 echo sprintf(
'%.5f/%.5f', $elapsed, $SPEED_CHECK_TOTAL).
' '.$str;
274 if ($log_file ==
'') {
275 error_log(sprintf(
'%.5f/%.5f', $elapsed, $SPEED_CHECK_TOTAL).
' '.$str);
277 log_write(sprintf(
'%.5f/%.5f', $elapsed, $SPEED_CHECK_TOTAL).
' '.$str, $log_file);
283 list($msec, $sec) = explode(
' ',microtime());
285 $SPEED_CHECK_LAST_HIT = ((double) $sec) + ((double) $msec);
300 function mem_check($print=NULL, $return_value=FALSE, $start_over=FALSE)
302 global $MEM_CHECK_FIRST_HIT, $MEM_CHECK_LAST_HIT;
304 $MEM_CHECK_FIRST_HIT = 0;
305 $MEM_CHECK_LAST_HIT = 0;
308 $hit = (int) (memory_get_usage() / 1024);
310 if (is_null($print) || in_array(
'current', $print)) {
314 if ($MEM_CHECK_LAST_HIT) {
315 if (is_null($print) || in_array(
'change', $print)) {
316 if ($hit > $MEM_CHECK_LAST_HIT) {
317 $mem .=
' (+ '.($hit - $MEM_CHECK_LAST_HIT).
' KB)';
319 if ($hit < $MEM_CHECK_LAST_HIT) {
320 $mem .=
' (- '.($MEM_CHECK_LAST_HIT - $hit).
' KB)';
325 if ($MEM_CHECK_FIRST_HIT) {
326 if (is_null($print) || in_array(
'total', $print)) {
327 if ($hit > $MEM_CHECK_FIRST_HIT) {
328 $mem .=
' [+ '.($hit - $MEM_CHECK_FIRST_HIT).
' KB TOTAL]';
330 if ($hit < $MEM_CHECK_FIRST_HIT) {
331 $mem .=
' [- '.($MEM_CHECK_FIRST_HIT - $hit).
' KB TOTAL]';
335 $MEM_CHECK_FIRST_HIT = $hit;
338 if (!$return_value) {
339 echo(
"<br><table cellpadding=0 cellspacing=0 border=0 bgcolor=#ffff88><tr><td><p style=\"color:red;font-weight:bold;font-family:sans-serif;font-size:13px;\">Mem: $mem</td></tr></table><br>");
342 $MEM_CHECK_LAST_HIT = $hit;
343 if ($return_value)
return $mem;
355 function print_function_list()
358 foreach (get_loaded_extensions() as $extension) {
359 echo
"<b>Extension: $extension</b><br>";
360 print_r (get_extension_funcs($extension));
362 echo
'<b>User-defined</b><br>';
363 $f = get_defined_functions();
364 print_r ($f[
'user']);
365 foreach (get_declared_classes() as $class) {
366 echo
"<b>Class Methods: $class</b><br>";
367 print_r(get_class_methods($class));
383 function pts_spew($i,$s)
385 if ($i != (
int) $i || !file_exists(
"/dev/pts/$i")) {
386 trigger_error(
"Can't spew to pts, \"$i\" is not a valid pts number.", E_USER_WARNING);
389 require_once(dirname(__FILE__).
'/../general/file_system.inc');
390 if (!string_to_file(
"$s\n",
"/dev/pts/$i")) {
391 trigger_error(
"Try ensuring that /dev/pts/[your_pts_number] is writable by the web server.<br>$ w # To find your pts<br>$ chmod a+w /dev/pts/[your_pts_number]<br>", E_USER_WARNING);
403 function get_calling_func()
406 $bt = debug_backtrace();
407 $file = substr($bt[1][
'file'], strrpos($bt[1][
'file']+1,
'/'));
410 if (isset($bt[2][
'class'])) {
411 $res = $bt[2][
'class'].
'::'.$bt[2][
'function'];
413 $res = $bt[2][
'function'];
416 $res .=
' ('.$file.
' line '.$bt[1][
'line'].
')';
434 function get_backtrace()
436 $bt = debug_backtrace();
441 foreach ($bt as $elem) {
443 if (isset($elem[
'line'])) $info =
'line='.$elem[
'line'];
446 if (isset($elem[
'file'])) {
447 $file = basename($elem[
'file']);
448 substr($file, 0, strpos($file,
'.'));
451 $class_name = substr($file, 0, strpos($file,
'.'));
452 if (empty($elem[
'class'])) {
453 $info .=
' file='.$file;
455 if ($class_name != $elem[
'class']) {
456 $info .=
' class='.$class_name.
' object='.$elem[
'class'];
458 $info .=
' class='.$elem[
'class'];
461 $stack[] =
'function '.$elem[
'function'].
'('.$info.
')';
474 function get_microtime()
476 list($usec, $sec) = explode(
' ', microtime());
490 function log_dump($var=NULL)
494 $var =
'---------- Debugging ----------';
496 error_log(
"\n".$count++.
': '.get_calling_func().
": \n".print_r($var, 1));