/// All rights reserved. Licensed under the GPL. /// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT) /** Pre-define basic components */ /***** Loading code pieces *****/ if (isset($uri)) { $codeName = $uri->uri['interfaceType']; } if ($context->getProperty('service.codecache', null) == true && file_exists(__TEXTCUBE_CACHE_DIR__ . '/code/' . $codeName)) { $codeCacheRead = true; require __TEXTCUBE_CACHE_DIR__ . '/code/' . $codeName; } else { $codeCacheRead = false; foreach ($context->getProperty('import.library') as $lib) { if (strpos($lib, 'DEBUG') === false) { importlib($lib); } else { if (defined('TCDEBUG')) { __tcSqlLogPoint($lib); } } } } if ($context->getProperty('service.codecache', null) == true && $codeCacheRead == false) { $libCode = new CodeCache(); $libCode->name = $codeName; foreach ($context->getProperty('import.library') as $lib) { array_push($libCode->sources, '/library/' . str_replace(".", "/", $lib) . '.php'); } $libCode->save(); unset($libCode); }
function __tcSqlLogDump() { global $__tcSqlLog, $__tcPageEndTime; global $service, $memcache; static $sLogPumped = false; if (!empty($sLogPumped)) { return; } $sLogPumped = true; __tcSqlLogPoint('shutdown'); $headers = array(); if (function_exists('apache_response_headers') || function_exists('headers_list')) { if (function_exists('apache_response_headers')) { flush(); $headers = apache_response_headers(); } else { $headers = headers_list(); } } $commentBlosk = false; foreach ($headers as $row) { if (strpos($row, '/xml') !== false || strpos($row, '+xml') !== false) { /* To check text/xml, application/xml and application/xml+blah, application/blah+xml... types */ $commentBlosk = true; break; } if (strpos($row, 'text/javascript') !== false) { return; } } if ($commentBlosk == true) { echo '<!--'; } if (!$commentBlosk) { print <<<EOS <style type='text/css'> /*<![CDATA[*/ \t.debugTable \t{ \t\tbackground-color: #fff; \t\tborder-left: 1px solid #999; \t\tborder-top: 1px solid #999; \t\tborder-collapse: collapse; \t\tmargin-bottom: 20px; \t} \t.debugTable * \t{ \t\tborder: none; \t\tmargin: 0; \t\tpadding: 0; \t} \t.debugTable td, .debugTable th \t{ \t\tborder-bottom: 1px solid #999; \t\tborder-right: 1px solid #999; \t\tcolor: #000; \t\tfont-family: Arial, Tahoma, Verdana, sans-serif; \t\tfont-size: 12px; \t\tpadding: 3px 5px; \t} \t.debugTable th \t{ \t\tbackground-color: #dedede; \t\ttext-align: center; \t} \ttr.debugSQLLine .rows \t{ \t\ttext-align: center; \t} \ttr.debugSQLLine .error \t{ \t\ttext-align: left; \t} \ttr.debugSQLLine .elapsed, tr.debugSQLLine .elapsedSum \t{ \t\ttext-align: right; \t} \ttr.debugSQLLine .backtrace \t{ \t\tfont-family: Courier, 'Courier new', monospace; \t\tfont-size: 11px; \t\tletter-spacing: -1px; \t} \ttr.debugCached *, tr.debugSystem * \t{ \t\tcolor: #888888 !important; \t} \t/* warning */ \ttr.debugWarning * \t{ \t\tbackground-color: #fefff1; \t\tcolor: #4b4b3b !important; \t} \ttr.debugWarning th \t{ \t\tbackground-color: #e5e5ca; \t} \t/* error */ \ttr.debugError * \t{ \t\tbackground-color: #fee5e5; \t\tcolor: #961f1d !important; \t} \ttr.debugError th \t{ \t\tbackground-color: #fccbca; \t} \ttfoot td \t{ \t\tpadding: 15px !important; \t\ttext-align: center; \t} /*]]>*/ </style> EOS; } $elapsed_total_db = 0; $elapsed = array(); $count = 1; $cached_count = 0; foreach ($__tcSqlLog as $c => $log) { $elapsed[$count] = array($log['elapsed'], $count, $log['cached'] ? "cached" : ""); $__tcSqlLog[$c]['percent'] = sprintf("%4.1f", $log['endtime'] * 100 / $__tcPageEndTime); $count++; } arsort($elapsed); $bgcolor = array(); foreach (array_splice($elapsed, 0, 5) as $e) { if ($e[2] != "cached") { $top5[$e[1]] = true; } } $count = 1; if (!$commentBlosk) { print '<table class="debugTable">'; print <<<THEAD \t\t<thead> \t\t\t<tr> \t\t\t\t<th>count</th><th class="sql">query string</th><th>elapsed (ms)</th><th>elapsed sum (ms)</th><th></th><th>rows</th><th>error</th><th>stack</th> \t\t\t</tr> \t\t</thead> THEAD; print '<tbody>'; } foreach ($__tcSqlLog as $c => $log) { $error = ''; $backtrace = ''; $frame_count = 1; $backtrace = __tcSqlLoggetCallstack($log['backtrace']); if ($log['errno']) { $error = "Error no. {$log['errno']} : {$log['error']}"; } $trclass = ''; $count_label = $count; if (!empty($error)) { $trclass = ' debugError'; } else { if (isset($top5[$count])) { $trclass = ' debugWarning'; } else { if ($log['cached'] == 1) { $error = "(cached)"; $trclass .= ' debugCached'; $cached_count++; } else { if ($log['cached'] == 2) { $error = ""; $trclass .= ' debugCached'; $count_label = ''; $backtrace = ''; } } } } if ($log['sql'] == '[shutdown]') { $error = ""; $log['sql'] = 'Shutdown'; $trclass .= ' debugSystem'; $count_label = ''; $backtrace = ''; } $elapsed_total_db += $log['elapsed']; $elapsed_total = $log['endtime']; $progress_bar = $log['percent'] / 2; //Max 50px; if (!$commentBlosk) { $log['sql'] = htmlspecialchars($log['sql']); $log['percent'] = "<div style='background:#f00;line-height:10px;width:{$progress_bar}px'> </div>"; print <<<TBODY \t\t<tr class="debugSQLLine{$trclass}"> \t\t\t<th>{$count_label}</th> \t\t\t<td class="code"><code>{$log['sql']}</code></td> \t\t\t<td class="elapsed">{$log['elapsed']}</td> \t\t\t<td class="elapsedSum">{$log['endtime']}</td> \t\t\t<td class="elapsedSum">{$log['percent']}</td> \t\t\t<td class="rows">{$log['rows']}</td> \t\t\t<td class="error">{$error}</td> \t\t\t<td class="backtrace"><pre>{$backtrace}</pre></td> \t\t</tr> TBODY; } else { $log['sql'] = str_replace('-->', '-- >', $log['sql']); print <<<TBODY =============================================================================================== {$count_label}:{$log['sql']} Elapsed:{$log['elapsed']} ms/End time:{$log['endtime']}/Percent:{$log['percent']}/Rows:{$log['rows']} rows {$error} {$backtrace} TBODY; } if ($log['cached'] < 2) { $count++; } } $count--; $real_query_count = $count - $cached_count; if (!$commentBlosk) { print '</tbody>'; print <<<TFOOT <tfoot> \t<tr> \t\t<td colspan='8'> \t\t{$count} ({$real_query_count}+{$cached_count} cache) Queries <br /> \t\t{$elapsed_total_db} ms elapsed in db query, overall {$elapsed_total} ms elapsed \t\t</td> \t</tr> </tfoot> TFOOT; print '</table>'; } global $service, $URLInfo, $suri; print '<div class="debugTable">' . CRLF; print '<h4>Current Database Management System :</h4>' . CRLF . '<p>' . POD::dbms() . ' ' . POD::version() . '</p>' . CRLF; print '<h4>SSL support : </h4>' . CRLF; if (isset($service['useSSL']) && $service['useSSL'] == true) { print '<p>Enabled</p>' . CRLF; } else { print '<p>Disabled</p>' . CRLF; } print '<h4>Cache system :</h4>' . CRLF; if (isset($service['pagecache']) && $service['pagecache'] == true) { print '<p>Page cache Enabled</p>' . CRLF; } else { print '<p>Page cache Disabled</p>' . CRLF; } if (isset($service['skincache']) && $service['skincache'] == true) { print '<p>Skin cache Enabled</p>' . CRLF; } else { print '<p>Skin cache Disabled</p>' . CRLF; } if (isset($service['memcached']) && $service['memcached'] == true) { print '<p>Memcached module Enabled</p>' . CRLF; } else { print '<p>Memcached module Disabled</p>' . CRLF; } if (!empty($service['debug_session_dump'])) { print '<h4>Session Information</h4>' . CRLF; print '<pre>session_id = ' . session_id() . CRLF; print '$_SESSION = '; print_r($_SESSION); print '$_COOKIE = '; print_r($_COOKIE); print '</pre>'; } if (!empty($service['debug_rewrite_module'])) { print '<h4>Path parse result</h4>' . CRLF; print '<pre>' . CRLF; print_r($URLInfo); print_r($suri); print '</pre>'; } print '</div>' . CRLF; if ($commentBlosk == true) { echo '-->'; } }