1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

Traffic counters tweak.

This commit is contained in:
Cameron
2019-02-10 14:51:51 -08:00
parent 535fef8799
commit 42147e2227
2 changed files with 669 additions and 622 deletions

View File

@@ -1,25 +1,31 @@
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| Copyright (C) 2008-2009 e107 Inc (e107.org)
| http://e107.org
|
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/db_debug_class.php,v $
| $Revision$
| $Date$
| $Author$
+----------------------------------------------------------------------------+
*/
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| Copyright (C) 2008-2009 e107 Inc (e107.org)
| http://e107.org
|
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/db_debug_class.php,v $
| $Revision$
| $Date$
| $Author$
+----------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
if(!defined('e107_INIT'))
{
exit;
}
class e107_db_debug
{
class e107_db_debug {
var $aSQLdetails = array(); // DB query analysis (in pieces for further analysis)
var $aDBbyTable = array();
var $aOBMarks = array(0 => ''); // Track output buffer level at each time mark
@@ -39,13 +45,14 @@ class e107_db_debug {
{
}
function e107_db_debug() {
function e107_db_debug()
{
global $eTimingStart;
$this->aTimeMarks[0]=array(
$this->aTimeMarks[0] = array(
'Index' => 0,
'What' => 'Start',
'%Time' => 0,
@@ -65,11 +72,12 @@ class e107_db_debug {
//
function Show_All()
{
$this->ShowIf('Debug Log', $this->Show_Log());
$this->ShowIf('Traffic Counters', e107::getSingleton('e107_traffic')->Display());
$this->ShowIf('Time Analysis', $this->Show_Performance());
$this->ShowIf('SQL Analysis', $this->Show_SQL_Details());
$this->ShowIf('Shortcodes / BBCode',$this->Show_SC_BB());
$this->ShowIf('Shortcodes / BBCode', $this->Show_SC_BB());
$this->ShowIf('Paths', $this->Show_PATH());
$this->ShowIf('Deprecated Function Usage', $this->Show_DEPRECATED());
@@ -78,46 +86,48 @@ class e107_db_debug {
$this->aIncList = get_included_files();
}
$this->ShowIf('Included Files: '.count($this->aIncList), $this->Show_Includes());
$this->ShowIf('Included Files: ' . count($this->aIncList), $this->Show_Includes());
}
function ShowIf($title,$str)
function ShowIf($title, $str)
{
if(!empty($str))
{
//e107::getRender()->setStyle('debug');
echo "<h4>".$title."</h4>";
echo "<h4>" . $title . "</h4>";
echo $str;
//e107::getRender()->tablerender($title, $str);
}
}
function Mark_Time($sMarker) { // Should move to traffic_class?
$timeNow=microtime();
$nMarks=++$this->nTimeMarks;
function Mark_Time($sMarker)
{ // Should move to traffic_class?
$timeNow = microtime();
$nMarks = ++$this->nTimeMarks;
if (!strlen($sMarker)) {
if(!strlen($sMarker))
{
$sMarker = "Mark not set";
}
$srch = array('[',']');
$repl = array("<small>","</small>");
$srch = array('[', ']');
$repl = array("<small>", "</small>");
$this->aTimeMarks[$nMarks]=array(
$this->aTimeMarks[$nMarks] = array(
'Index' => ($this->nTimeMarks),
'What' => str_replace($srch,$repl,$sMarker),
'What' => str_replace($srch, $repl, $sMarker),
'%Time' => 0,
'%DB Time' => 0,
'%DB Count' => 0,
'Time' => $timeNow,
'DB Time' => 0,
'DB Count' => 0,
'Memory' => ((function_exists("memory_get_usage"))? memory_get_usage() : 0)
'Memory' => ((function_exists("memory_get_usage")) ? memory_get_usage() : 0)
);
$this->aOBMarks[$nMarks]=ob_get_level().'('.ob_get_length().')';
$this->curTimeMark=$sMarker;
$this->aOBMarks[$nMarks] = ob_get_level() . '(' . ob_get_length() . ')';
$this->curTimeMark = $sMarker;
// Add any desired notes to $aMarkNotes[$nMarks]... e.g.
//global $eTimingStart;
@@ -135,28 +145,30 @@ class e107_db_debug {
*/
function Mark_Query($query, $rli, $origQryRes, $aTrace, $mytime, $curtable)
{
// global $sql;
$sql = e107::getDb( $rli);
$sql = e107::getDb($rli);
// Explain the query, if possible...
list($qtype,$args) = explode(" ", ltrim($query), 2);
list($qtype, $args) = explode(" ", ltrim($query), 2);
$nFields=0;
$bExplained = FALSE;
unset($args);
$nFields = 0;
$bExplained = false;
$ExplainText = '';
// Note the subtle bracket in the second comparison! Also, strcasecmp() returns zero on match
if (!strcasecmp($qtype,'SELECT') || !strcasecmp($qtype,'(SELECT'))
if(!strcasecmp($qtype, 'SELECT') || !strcasecmp($qtype, '(SELECT'))
{ // It's a SELECT statement - explain it
// $rli should always be set by caller
// $sQryRes = (is_null($rli) ? mysql_query("EXPLAIN {$query}") : mysql_query("EXPLAIN {$query}", $rli));
$sQryRes = $sql->gen("EXPLAIN {$query}");
if ($sQryRes) // There's something to explain
if($sQryRes) // There's something to explain
{
//$nFields = mysql_num_fields($sQryRes);
$nFields = $sql->columnCount($sQryRes); // mysql_num_fields($sQryRes);
$bExplained = TRUE;
$bExplained = true;
}
}
else
@@ -172,23 +184,23 @@ class e107_db_debug {
$t['marker'] = $this->curTimeMark;
$t['caller'] = "$sCallingFile($sCallingLine)";
$t['query'] = $query;
$t['ok'] = ($sQryRes !==false) ? true : false;
$t['ok'] = ($sQryRes !== false) ? true : false;
$t['error'] = $sQryRes ? '' : $sql->getLastErrorText(); // mysql_error();
$t['nFields'] = $nFields;
$t['time'] = $mytime;
if ($bExplained)
if($bExplained)
{
$bRowHeaders=FALSE;
$bRowHeaders = false;
// while ($row = @mysql_fetch_assoc($sQryRes))
while ($row = $sql->fetch())
while($row = $sql->fetch())
{
if (!$bRowHeaders)
if(!$bRowHeaders)
{
$bRowHeaders=TRUE;
$t['explain']="<tr><td class='forumheader3'><b>".implode("</b></td><td class='forumheader3'><b>", array_keys($row))."</b></td></tr>\n";
$bRowHeaders = true;
$t['explain'] = "<tr><td class='forumheader3'><b>" . implode("</b></td><td class='forumheader3'><b>", array_keys($row)) . "</b></td></tr>\n";
}
$t['explain'] .= "<tr><td class='forumheader3'>".implode("&nbsp;</td><td class='forumheader3'>", array_values($row))."&nbsp;</td></tr>\n";
$t['explain'] .= "<tr><td class='forumheader3'>" . implode("&nbsp;</td><td class='forumheader3'>", array_values($row)) . "&nbsp;</td></tr>\n";
}
}
else
@@ -199,7 +211,7 @@ class e107_db_debug {
$this->aTimeMarks[$this->nTimeMarks]['DB Time'] += $mytime;
$this->aTimeMarks[$this->nTimeMarks]['DB Count']++;
if (array_key_exists($curtable, $this->aDBbyTable))
if(array_key_exists($curtable, $this->aDBbyTable))
{
$this->aDBbyTable[$curtable]['DB Time'] += $mytime;
$this->aDBbyTable[$curtable]['DB Count']++;
@@ -215,32 +227,36 @@ class e107_db_debug {
}
function Show_SQL_Details($force = false)
{
function Show_SQL_Details($force=false) {
global $sql;
//
// Show stats from aSQLdetails array
//
if (!E107_DBG_SQLQUERIES && !E107_DBG_SQLDETAILS && ($force === false))
if(!E107_DBG_SQLQUERIES && !E107_DBG_SQLDETAILS && ($force === false))
{
return false;
}
$text='';
$nQueries=$sql->db_QueryCount();
$text = '';
$nQueries = $sql->db_QueryCount();
if (!$nQueries) return $text;
if(!$nQueries)
{
return $text;
}
//
// ALWAYS summarize query errors
//
$badCount=0;
$okCount=0;
$badCount = 0;
$okCount = 0;
foreach ($this->aSQLdetails as $cQuery)
foreach($this->aSQLdetails as $cQuery)
{
if ($cQuery['ok']==1)
if($cQuery['ok'] == 1)
{
$okCount++;
}
@@ -250,16 +266,18 @@ class e107_db_debug {
}
}
if ($badCount) {
if($badCount)
{
$text .= "\n<table class='fborder table table-striped table-bordered'>\n";
$text .= "<tr><td class='fcaption' colspan='2'><b>$badCount Query Errors!</b></td></tr>\n";
$text .= "<tr><td class='fcaption'><b>Index</b></td><td class='fcaption'><b>Query / Error</b></td></tr>\n";
foreach ($this->aSQLdetails as $idx => $cQuery) {
if (!$cQuery['ok'])
foreach($this->aSQLdetails as $idx => $cQuery)
{
if(!$cQuery['ok'])
{
$text .= "<tr><td class='forumheader3' rowspan='2' style='text-align:right'>{$idx}&nbsp;</td>
<td class='forumheader3'>".$cQuery['query']."</td></tr>\n<tr><td class='forumheader3'>".$cQuery['error']."</td></tr>\n";
<td class='forumheader3'>" . $cQuery['query'] . "</td></tr>\n<tr><td class='forumheader3'>" . $cQuery['error'] . "</td></tr>\n";
}
}
$text .= "\n</table><br />\n";
@@ -269,16 +287,16 @@ class e107_db_debug {
// Optionally list good queries
//
if ($okCount && E107_DBG_SQLDETAILS)
if($okCount && E107_DBG_SQLDETAILS)
{
$text .= "\n<table class='fborder table table-striped table-bordered'>\n";
$text .= "<tr><td class='fcaption' colspan='3'><b>".$this->countLabel($okCount)." Good Queries</b></td></tr>\n";
$text .= "<tr><td class='fcaption' colspan='3'><b>" . $this->countLabel($okCount) . " Good Queries</b></td></tr>\n";
$text .= "<tr><td class='fcaption'><b>Index</b></td><td class='fcaption'><b>Qtime</b></td><td class='fcaption'><b>Query</b></td></tr>\n
<tr><td class='fcaption'>&nbsp;</td><td class='fcaption'><b>(msec)</b></td><td class='fcaption'>&nbsp;</td></tr>\n
";
$count = 0;
foreach ($this->aSQLdetails as $idx => $cQuery)
foreach($this->aSQLdetails as $idx => $cQuery)
{
if($count > 500)
{
@@ -287,18 +305,17 @@ class e107_db_debug {
}
if ($cQuery['ok'])
if($cQuery['ok'])
{
$text .= "<tr><td class='forumheader3' style='text-align:right'>{$idx}&nbsp;</td>
<td class='forumheader3' style='text-align:right'>".number_format($cQuery['time'] * 1000.0, 4)."&nbsp;</td>
<td class='forumheader3'>".$cQuery['query'].'<br />['.$cQuery['marker']." - ".$cQuery['caller']."]</td></tr>\n";
<td class='forumheader3' style='text-align:right'>" . number_format($cQuery['time'] * 1000.0, 4) . "&nbsp;</td>
<td class='forumheader3'>" . $cQuery['query'] . '<br />[' . $cQuery['marker'] . " - " . $cQuery['caller'] . "]</td></tr>\n";
$count++;
}
}
$text .= "\n</table><br />\n";
}
@@ -306,23 +323,25 @@ class e107_db_debug {
//
// Optionally list query details
//
if (E107_DBG_SQLDETAILS)
if(E107_DBG_SQLDETAILS)
{
$count = 0;
foreach ($this->aSQLdetails as $idx => $cQuery)
foreach($this->aSQLdetails as $idx => $cQuery)
{
$text .= "\n<table class='fborder table table-striped table-bordered' style='width: 100%;'>\n";
$text .= "<tr><td class='forumheader3' colspan='".$cQuery['nFields']."'><b>".$idx.") Query:</b> [".$cQuery['marker']." - ".$cQuery['caller']."]<br />".$cQuery['query']."</td></tr>\n";
if (isset($cQuery['explain'])) {
$text .= "<tr><td class='forumheader3' colspan='" . $cQuery['nFields'] . "'><b>" . $idx . ") Query:</b> [" . $cQuery['marker'] . " - " . $cQuery['caller'] . "]<br />" . $cQuery['query'] . "</td></tr>\n";
if(isset($cQuery['explain']))
{
$text .= $cQuery['explain'];
}
if (strlen($cQuery['error'])) {
$text .= "<tr><td class='forumheader3' ><b>Error in query:</b></td></tr>\n<tr><td class='forumheader3'>".$cQuery['error']."</td></tr>\n";
if(strlen($cQuery['error']))
{
$text .= "<tr><td class='forumheader3' ><b>Error in query:</b></td></tr>\n<tr><td class='forumheader3'>" . $cQuery['error'] . "</td></tr>\n";
}
$text .= "<tr><td class='forumheader3' colspan='".$cQuery['nFields']."'><b>Query time:</b> ".number_format($cQuery['time'] * 1000.0, 4).' (ms)</td></tr>';
$text .= "<tr><td class='forumheader3' colspan='" . $cQuery['nFields'] . "'><b>Query time:</b> " . number_format($cQuery['time'] * 1000.0, 4) . ' (ms)</td></tr>';
$text .= '</table><br />'."\n";
$text .= '</table><br />' . "\n";
if($count > 500)
{
@@ -340,6 +359,7 @@ class e107_db_debug {
function countLabel($amount)
{
if($amount < 30)
{
$inc = 'label-success';
@@ -353,22 +373,23 @@ class e107_db_debug {
$inc = 'label-danger label-important';
}
return "<span class='label ".$inc."'>".$amount."</span>";
return "<span class='label " . $inc . "'>" . $amount . "</span>";
}
function save($log)
{
e107::getMessage()->addDebug("Saving a log");
$titles = array_keys($this->aTimeMarks[0]);
$text = implode("\t\t\t",$titles)."\n\n";
$text = implode("\t\t\t", $titles) . "\n\n";
foreach($this->aTimeMarks as $item)
{
$item['What'] = str_pad($item['What'],50," ",STR_PAD_RIGHT);
$text .= implode("\t\t\t",$item)."\n";
$item['What'] = str_pad($item['What'], 50, " ", STR_PAD_RIGHT);
$text .= implode("\t\t\t", $item) . "\n";
}
file_put_contents($log, $text, FILE_APPEND);
@@ -376,12 +397,12 @@ class e107_db_debug {
}
private function highlight($label, $value=0,$threshold=0)
private function highlight($label, $value = 0, $threshold = 0)
{
if($value > $threshold)
{
return "<span class='label label-danger'>".$label."</span>";
return "<span class='label label-danger'>" . $label . "</span>";
}
return $label;
@@ -391,6 +412,7 @@ class e107_db_debug {
function Show_Performance()
{
//
// Stats by Time Marker
//
@@ -422,10 +444,10 @@ class e107_db_debug {
// Calculate Memory Usage per entry.
$prevMem = 0;
foreach($this->aTimeMarks as $k=>$v)
foreach($this->aTimeMarks as $k => $v)
{
$prevKey = $k-1;
$prevKey = $k - 1;
if(!empty($prevKey))
{
@@ -436,7 +458,6 @@ class e107_db_debug {
}
while(list($tKey, $tMarker) = each($this->aTimeMarks))
{
if(!$bRowHeaders)
@@ -465,7 +486,6 @@ class e107_db_debug {
}
// $tMem = ($tMarker['Memory'] - $aSum['Memory']);
$tMem = ($tMarker['Memory']);
@@ -480,8 +500,8 @@ class e107_db_debug {
$tUsage = $tMarker['Memory Used'];
$tMarker['Memory Used'] = number_format($tUsage / 1024.0, 1);
$tMarker['Memory Used'] = $this->highlight($tMarker['Memory Used'],$tUsage,400000);
/*
$tMarker['Memory Used'] = $this->highlight($tMarker['Memory Used'], $tUsage, 400000);
/*
if($tUsage > 400000) // Highlight high memory usage.
{
$tMarker['Memory Used'] = "<span class='label label-danger'>".$tMarker['Memory Used']."</span>";
@@ -511,7 +531,7 @@ class e107_db_debug {
$aSum['DB Time'] += $tMarker['DB Time'];
$aSum['DB Count'] += $tMarker['DB Count'];
$tMarker['Time'] = number_format($thisDelta * 1000.0, 1);
$tMarker['Time'] = $this->highlight($tMarker['Time'],$thisDelta,.2);
$tMarker['Time'] = $this->highlight($tMarker['Time'], $thisDelta, .2);
$tMarker['%Time'] = $totTime ? number_format(100.0 * ($thisDelta / $totTime), 0) : 0;
@@ -628,14 +648,15 @@ class e107_db_debug {
return $text;
}
function logDeprecated(){
function logDeprecated()
{
$back_trace = debug_backtrace();
print_r($back_trace);
$this->deprecated_funcs[] = array (
'func' => (isset($back_trace[1]['type']) && ($back_trace[1]['type'] == '::' || $back_trace[1]['type'] == '->') ? $back_trace[1]['class'].$back_trace[1]['type'].$back_trace[1]['function'] : $back_trace[1]['function']),
$this->deprecated_funcs[] = array(
'func' => (isset($back_trace[1]['type']) && ($back_trace[1]['type'] == '::' || $back_trace[1]['type'] == '->') ? $back_trace[1]['class'] . $back_trace[1]['type'] . $back_trace[1]['function'] : $back_trace[1]['function']),
'file' => $back_trace[1]['file'],
'line' => $back_trace[1]['line']
);
@@ -644,21 +665,25 @@ class e107_db_debug {
function logCode($type, $code, $parm, $details)
{
if (!E107_DBG_BBSC)
if(!E107_DBG_BBSC)
{
return FALSE;
return false;
}
$this->scbbcodes[$this->scbcount]['type'] = $type;
$this->scbbcodes[$this->scbcount]['code'] = $code;
$this->scbbcodes[$this->scbcount]['parm'] = (string)$parm;
$this->scbbcodes[$this->scbcount]['parm'] = (string) $parm;
$this->scbbcodes[$this->scbcount]['details'] = $details;
$this->scbcount ++;
$this->scbcount++;
return null;
}
function Show_SC_BB($force=false)
function Show_SC_BB($force = false)
{
if (!E107_DBG_BBSC && ($force === false))
if(!E107_DBG_BBSC && ($force === false))
{
return false;
}
@@ -675,30 +700,32 @@ class e107_db_debug {
</thead>
<tbody>\n";
$description = array(1=>'Bbcode',2=>'Shortcode',3=>'Wrapper', 4=>'Shortcode Override', -2 => 'Shortcode Failure');
$style = array(1 => 'label-info', 2=>'label-primary', 3=>'label-warning', 'label-danger', -2 => 'label-danger');
$description = array(1 => 'Bbcode', 2 => 'Shortcode', 3 => 'Wrapper', 4 => 'Shortcode Override', -2 => 'Shortcode Failure');
$style = array(1 => 'label-info', 2 => 'label-primary', 3 => 'label-warning', 'label-danger', -2 => 'label-danger');
foreach($this -> scbbcodes as $codes)
foreach($this->scbbcodes as $codes)
{
$type = $codes['type'];
$text .= "<tr>
<td class='forumheader3' style='width: 10%;'><span class='label ".$style[$type]."'>".($description[$type])."</span></td>
<td class='forumheader3' style='width: auto;'>".(isset($codes['code']) ? $codes['code'] : "&nbsp;")."</td>
<td class='forumheader3' style='width: auto;'>".($codes['parm'] ? $codes['parm'] : "&nbsp;")."</td>
<td class='forumheader3' style='width: 40%;'>".($codes['details'] ? $codes['details'] : "&nbsp;")."</td>
<td class='forumheader3' style='width: 10%;'><span class='label " . $style[$type] . "'>" . ($description[$type]) . "</span></td>
<td class='forumheader3' style='width: auto;'>" . (isset($codes['code']) ? $codes['code'] : "&nbsp;") . "</td>
<td class='forumheader3' style='width: auto;'>" . ($codes['parm'] ? $codes['parm'] : "&nbsp;") . "</td>
<td class='forumheader3' style='width: 40%;'>" . ($codes['details'] ? $codes['details'] : "&nbsp;") . "</td>
</tr>\n";
}
$text .= "</tbody></table>";
return $text;
}
function Show_PATH($force=false)
function Show_PATH($force = false)
{
if (!E107_DBG_PATH && ($force === false))
if(!E107_DBG_PATH && ($force === false))
{
return FALSE;
return false;
}
global $e107;
@@ -718,22 +745,22 @@ class e107_db_debug {
$inc = array(
'BOOTSTRAP','HEADERF','FOOTERF','FILE_UPLOADS','FLOODPROTECT','FLOODTIMEOUT','CHARSET',
'GUESTS_ONLINE','MEMBERS_ONLINE','PAGE_NAME','STANDARDS_MODE','TIMEOFFSET',
'TOTAL_ONLINE','THEME','THEME_ABS','THEME_LAYOUT', 'THEME_LEGACY','THEME_STYLE','META_OG','META_DESCRIPTION','MPREFIX','VIEWPORT','BODYTAG','CSSORDER'
'BOOTSTRAP', 'HEADERF', 'FOOTERF', 'FILE_UPLOADS', 'FLOODPROTECT', 'FLOODTIMEOUT', 'CHARSET',
'GUESTS_ONLINE', 'MEMBERS_ONLINE', 'PAGE_NAME', 'STANDARDS_MODE', 'TIMEOFFSET',
'TOTAL_ONLINE', 'THEME', 'THEME_ABS', 'THEME_LAYOUT', 'THEME_LEGACY', 'THEME_STYLE', 'META_OG', 'META_DESCRIPTION', 'MPREFIX', 'VIEWPORT', 'BODYTAG', 'CSSORDER'
);
$userCon = get_defined_constants(true);
ksort($userCon['user']);
foreach($userCon['user'] as $k=>$v)
foreach($userCon['user'] as $k => $v)
{
if(E107_DBG_ALLERRORS || in_array($k,$inc) || substr($k,0,5) == 'ADMIN' || substr($k,0,2) == 'E_' || substr($k,0,2) == 'e_' || substr($k,0,4) == 'E107' || substr($k,0,4) == 'SITE' || substr($k,0,4) == 'USER' || substr($k,0,4) == 'CORE')
if(E107_DBG_ALLERRORS || in_array($k, $inc) || substr($k, 0, 5) == 'ADMIN' || substr($k, 0, 2) == 'E_' || substr($k, 0, 2) == 'e_' || substr($k, 0, 4) == 'E107' || substr($k, 0, 4) == 'SITE' || substr($k, 0, 4) == 'USER' || substr($k, 0, 4) == 'CORE')
{
$text .= "
<tr>
<td class='forumheader3'>".$k."</td>
<td class='forumheader3'>".htmlspecialchars($v)."</td>
<td class='forumheader3'>" . $k . "</td>
<td class='forumheader3'>" . htmlspecialchars($v) . "</td>
</tr>";
}
}
@@ -745,38 +772,38 @@ class e107_db_debug {
<tr>
<td class='forumheader3'>SQL Language</td>
<td class='forumheader3'>".$sql->mySQLlanguage."</td>
<td class='forumheader3'>" . $sql->mySQLlanguage . "</td>
</tr>
";
if($_SERVER['E_DEV'] == 'true')
{
$text .= "
<tr>
<td class='forumheader3' colspan='2'><pre>".htmlspecialchars(print_r($e107,TRUE))."</pre></td>
<td class='forumheader3' colspan='2'><pre>" . htmlspecialchars(print_r($e107, true)) . "</pre></td>
</tr>";
}
$text .="
$text .= "
<tr>
<td class='fcaption' colspan='2'><h2>Session</h2></td>
</tr>
<tr>
<td class='forumheader3'>Session lifetime</td>
<td class='forumheader3'>".$sess->getOption('lifetime')." seconds</td>
<td class='forumheader3'>" . $sess->getOption('lifetime') . " seconds</td>
</tr>
<tr>
<td class='forumheader3'>Session domain</td>
<td class='forumheader3'>".$sess->getOption('domain')."</td>
<td class='forumheader3'>" . $sess->getOption('domain') . "</td>
</tr>
<tr>
<td class='forumheader3'>Session save method</td>
<td class='forumheader3'>".$sess->getSaveMethod()."</td>
<td class='forumheader3'>" . $sess->getSaveMethod() . "</td>
</tr>
<tr>
<td class='forumheader3' colspan='2'><pre>".htmlspecialchars(print_r($_SESSION,TRUE))."</pre></td>
<td class='forumheader3' colspan='2'><pre>" . htmlspecialchars(print_r($_SESSION, true)) . "</pre></td>
</tr>
</tbody>
@@ -786,9 +813,10 @@ class e107_db_debug {
}
function Show_DEPRECATED($force=false)
function Show_DEPRECATED($force = false)
{
if (!E107_DBG_DEPRECATED && ($force === false))
if(!E107_DBG_DEPRECATED && ($force === false))
{
return false;
}
@@ -814,6 +842,7 @@ class e107_db_debug {
</tr>\n";
}
$text .= "</tbody></table>";
return $text;
}
}
@@ -821,10 +850,12 @@ class e107_db_debug {
/**
* var_dump to debug log
*
* @param mixed $message
*/
function dump($message, $TraceLev= 1)
function dump($message, $TraceLev = 1)
{
ob_start();
var_dump($message);
$content = ob_get_contents();
@@ -834,7 +865,7 @@ class e107_db_debug {
$this->aLog[] = array(
'Message' => $content,
'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'].$bt[$TraceLev]['type'].$bt[$TraceLev]['function'].'()' : $bt[$TraceLev]['function']).'()',
'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'] . $bt[$TraceLev]['type'] . $bt[$TraceLev]['function'] . '()' : $bt[$TraceLev]['function']) . '()',
'File' => varset($bt[$TraceLev]['file']),
'Line' => varset($bt[$TraceLev]['line'])
);
@@ -842,50 +873,61 @@ class e107_db_debug {
// $this->aLog[] = array ('Message' => $content, 'Function' => '', 'File' => '', 'Line' => '' );
}
//
// Simple debug-level 'console' log
// Record a "nice" debug message with
// $db_debug->log("message");
//
function log($message,$TraceLev=1)
/**
* @desc Simple debug-level 'console' log
* Record a "nice" debug message with
* $db_debug->log("message");
* @param string $message
* @param int $TraceLev
* @return bool true on success , false on error
*/
public function log($message, $TraceLev = 1)
{
if(is_array($message) || is_object($message))
{
$message = "<pre>".print_r($message,true)."</pre>";
$message = "<pre>" . print_r($message, true) . "</pre>";
}
if (!deftrue('E107_DBG_BASIC') && !deftrue('E107_DBG_ALLERRORS') && !deftrue('E107_DBG_SQLDETAILS') && !deftrue('E107_DBG_NOTICES'))
if(!deftrue('E107_DBG_BASIC') && !deftrue('E107_DBG_ALLERRORS') && !deftrue('E107_DBG_SQLDETAILS') && !deftrue('E107_DBG_NOTICES'))
{
return false;
}
if ($TraceLev)
if($TraceLev)
{
$bt = debug_backtrace();
$this->aLog[] = array (
$this->aLog[] = array(
'Message' => $message,
'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'].$bt[$TraceLev]['type'].$bt[$TraceLev]['function'].'()' : $bt[$TraceLev]['function']).'()',
'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'] . $bt[$TraceLev]['type'] . $bt[$TraceLev]['function'] . '()' : $bt[$TraceLev]['function']) . '()',
'File' => varset($bt[$TraceLev]['file']),
'Line' => varset($bt[$TraceLev]['line'])
);
} else {
$this->aLog[] = array (
}
else
{
$this->aLog[] = array(
'Message' => $message,
'Function' => '',
'File' => '',
'Line' => ''
);
}
return true;
}
/**
* @return bool|string
*/
function Show_Log()
{
if (empty($this->aLog))
if(empty($this->aLog))
{
return FALSE;
return false;
}
//
// Dump the debug log
@@ -893,17 +935,17 @@ class e107_db_debug {
$text = "\n<table class='fborder table table-striped'>\n";
$bRowHeaders=FALSE;
$bRowHeaders = false;
foreach ($this->aLog as $curLog)
foreach($this->aLog as $curLog)
{
if (!$bRowHeaders)
if(!$bRowHeaders)
{
$bRowHeaders = true;
$text .= "<tr><td class='fcaption' style='text-align:left'><b>".implode("</b></td><td class='fcaption' style='text-align:left'><b>", array_keys($curLog))."</b></td></tr>\n";
$text .= "<tr><td class='fcaption' style='text-align:left'><b>" . implode("</b></td><td class='fcaption' style='text-align:left'><b>", array_keys($curLog)) . "</b></td></tr>\n";
}
$text .= "<tr ><td class='forumheader3'>".implode("&nbsp;</td><td class='forumheader3'>", array_values($curLog))."&nbsp;</td></tr>\n";
$text .= "<tr ><td class='forumheader3'>" . implode("&nbsp;</td><td class='forumheader3'>", array_values($curLog)) . "&nbsp;</td></tr>\n";
}
$text .= "</table><br />\n";
@@ -911,63 +953,77 @@ class e107_db_debug {
return $text;
}
function Show_Includes($force=false)
function Show_Includes($force = false)
{
if (!E107_DBG_INCLUDES && ($force === false)) return false;
if(!E107_DBG_INCLUDES && ($force === false))
{
return false;
}
$text = "<table class='fborder table table-striped'>\n";
$text .= "<tr><td class='forumheader3'>".
implode("&nbsp;</td></tr>\n<tr><td class='forumheader3'>", $this->aIncList).
$text .= "<tr><td class='forumheader3'>" .
implode("&nbsp;</td></tr>\n<tr><td class='forumheader3'>", $this->aIncList) .
"&nbsp;</td></tr>\n";
$text .= "</table>\n";
return $text;
}
}
}
//
// Helper functions (not part of the class)
//
function e107_debug_shutdown()
{
function e107_debug_shutdown()
{
if(e_AJAX_REQUEST) // extra output will break json ajax returns ie. comments
{
return;
}
global $error_handler,$e107_Clean_Exit,$In_e107_Footer,$ADMIN_DIRECTORY;
if (isset($e107_Clean_Exit)) return;
global $error_handler, $e107_Clean_Exit, $In_e107_Footer, $ADMIN_DIRECTORY;
if(isset($e107_Clean_Exit))
{
return;
}
if (!isset($In_e107_Footer))
if(!isset($In_e107_Footer))
{
if (defset('ADMIN_AREA'))
if(defset('ADMIN_AREA'))
{
$filewanted=realpath(dirname(__FILE__)).'/../'.$ADMIN_DIRECTORY.'footer.php';
$filewanted = realpath(dirname(__FILE__)) . '/../' . $ADMIN_DIRECTORY . 'footer.php';
require_once($filewanted);
} else if (defset('USER_AREA'))
}
elseif(defset('USER_AREA'))
{
$filewanted=realpath(dirname(__FILE__)).'/../'.FOOTERF;
$filewanted = realpath(dirname(__FILE__)) . '/../' . FOOTERF;
require_once($filewanted);
}
}
//
// Error while in the footer, or during startup, or during above processing
//
if (isset($e107_Clean_Exit)) return; // We've now sent a footer...
if(isset($e107_Clean_Exit))
{
return;
} // We've now sent a footer...
// echo isset($In_e107_Footer) ? "In footer" : "In startup".'<br />';
while (ob_get_level() > 0) {
while(ob_get_level() > 0)
{
ob_end_flush();
}
if (isset($error_handler))
if(isset($error_handler))
{
if($error_handler->return_errors())
{
echo "<br /><div 'e107_debug php_err'><h3>PHP Errors:</h3><br />".$error_handler->return_errors()."</div>\n";
echo "<br /><div 'e107_debug php_err'><h3>PHP Errors:</h3><br />" . $error_handler->return_errors() . "</div>\n";
echo "</body></html>";
}
}
@@ -977,6 +1033,5 @@ function e107_debug_shutdown()
echo "</body></html>";
}
}
}
?>

View File

@@ -51,6 +51,8 @@ class e_db_pdo implements e_db
private $pdo = true; // using PDO or not.
private $pdoBind = false;
private $traffic;
/**
* Constructor - gets language options from the cookie or session
@@ -58,16 +60,16 @@ class e_db_pdo implements e_db
*/
public function __construct()
{
global $pref, $db_defaultPrefix;
/*
if((PHP_MAJOR_VERSION > 6) || !function_exists('mysql_connect') || (defined('e_PDO') && e_PDO === true))
{
$this->pdo = true;
}
*/e107::getSingleton('e107_traffic')->BumpWho('Create db object', 1);
*/
$this->traffic = e107::getSingleton('e107_traffic');
$this->traffic->BumpWho('Create db object', 1);
$this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden
@@ -76,17 +78,7 @@ class e_db_pdo implements e_db
$this->mySQLport = intval($port);
}
/*$langid = (isset($pref['cookie_name'])) ? 'e107language_'.$pref['cookie_name'] : 'e107language_temp';
if (isset($pref['user_tracking']) && ($pref['user_tracking'] == 'session'))
{
if (!isset($_SESSION[$langid])) { return; }
$this->mySQLlanguage = $_SESSION[$langid];
}
else
{
if (!isset($_COOKIE[$langid])) { return; }
$this->mySQLlanguage = $_COOKIE[$langid];
}*/
// Detect is already done in language handler, use it if not too early
if(defined('e_LANGUAGE')) $this->mySQLlanguage = e107::getLanguage()->e_language;
}
@@ -196,7 +188,7 @@ class e_db_pdo implements e_db
{
global $db_ConnectionID, $db_defaultPrefix;
e107::getSingleton('e107_traffic')->BumpWho('db Connect', 1);
$this->traffic->BumpWho('db Connect', 1);
$this->mySQLserver = $mySQLserver;
$this->mySQLuser = $mySQLuser;
@@ -441,8 +433,8 @@ class e_db_pdo implements e_db
$e = microtime();
e107::getSingleton('e107_traffic')->Bump('db_Query', $b, $e);
$mytime = e107::getSingleton('e107_traffic')->TimeDelta($b,$e);
$this->traffic->Bump('db_Query', $b, $e);
$mytime = $this->traffic->TimeDelta($b,$e);
$db_time += $mytime;
$this->mySQLresult = $sQryRes;
@@ -1360,7 +1352,7 @@ class e_db_pdo implements e_db
/** @var PDOStatement $resource */
$resource = $this->mySQLresult;
$row = $resource->fetch($type);
e107::getSingleton('e107_traffic')->Bump('db_Fetch', $b);
$this->traffic->Bump('db_Fetch', $b);
if ($row)
{
$this->dbError('db_Fetch');
@@ -1453,7 +1445,7 @@ class e_db_pdo implements e_db
function close()
{
$this->provide_mySQLaccess();
e107::getSingleton('e107_traffic')->BumpWho('db Close', 1);
$this->traffic->BumpWho('db Close', 1);
$this->mySQLaccess = NULL; // correct way to do it when using shared links.
$this->dbError('dbClose');
}