shutdown(); // System browser CACHE control - defaults to no cache; override in e107_config or on the fly // This is temporary solution, we'll implement more flexible way for cache control override // per page, more investigation needed about cache related headers, browser quirks etc // Auto-detect from session (registered per page, per user session) if(!defined('e_NOCACHE')) { define('e_NOCACHE', !e107::canCache()); } // // SHUTDOWN SEQUENCE // // The following items have been carefully designed so page processing will finish properly // Please DO NOT re-order these items without asking first! You WILL break something ;) // These letters match the ADMIN footer (that's why there is B.1,B.2) // // A Ensure sql and traffic objects exist // [Next few ONLY if a regular page; not done for popups] // B.1 Clear cache (if admin page, not here) // B.2 Send the footer templated data // C Dump any/all traffic and debug information // [end of regular-page-only items] // D Close the database connection // E Themed footer code // F Configured footer scripts // G Browser-Server time sync script (must be the last one generated/sent) // H Final HTML (/body, /html) // I collect and send buffered page, along with needed headers // $e107 = e107::getInstance(); $sql = e107::getDb(); $pref = e107::getPref(); if (varset($e107_popup) != 1) { // // B.1 Clear cache (admin-only) // // // B.2 Send footer template, stop timing, send simple page stats // if(!deftrue('e_IFRAME')) { parseheader((varset($ph) ? $cust_footer : $FOOTER)); } $eTimingStop = microtime(); global $eTimingStart; $clockTime = e107::getSingleton('e107_traffic')->TimeDelta($eTimingStart, $eTimingStop); $dbPercent = 100.0 * $db_time / $clockTime; // Format for display or logging $rendertime = number_format($clockTime, 2); // Clock time during page render $db_time = number_format($db_time, 2); // Clock time in DB render $dbPercent = number_format($dbPercent, 0); // DB as percent of clock $memuse = eHelper::getMemoryUsage(); // Memory at end, in B/KB/MB/GB ;) $queryCount = $sql->db_QueryCount(); $rinfo = ''; $logLine = ''; if ($pref['log_page_accesses']) { // Collect the first batch of data to log $logLine .= "'".($now = time())."','".gmstrftime('%y-%m-%d %H:%M:%S', $now)."','".e107::getIPHandler()->getIP(FALSE)."','".e_PAGE.'?'.e_QUERY."','".$rendertime."','".$db_time."','".$queryCount."','".$memuse."','".$_SERVER['HTTP_USER_AGENT']."','{$_SERVER["REQUEST_METHOD"]}'"; } if (function_exists('getrusage')) { $ru = getrusage(); $cpuUTime = $ru['ru_utime.tv_sec'] + ($ru['ru_utime.tv_usec'] * 1e-6); $cpuSTime = $ru['ru_stime.tv_sec'] + ($ru['ru_stime.tv_usec'] * 1e-6); $cpuUStart = $eTimingStartCPU['ru_utime.tv_sec'] + ($eTimingStartCPU['ru_utime.tv_usec'] * 1e-6); $cpuSStart = $eTimingStartCPU['ru_stime.tv_sec'] + ($eTimingStartCPU['ru_stime.tv_usec'] * 1e-6); $cpuStart = $cpuUStart + $cpuSStart; $cpuTot = $cpuUTime + $cpuSTime; $cpuTime = $cpuTot - $cpuStart; $cpuPct = 100.0 * $cpuTime / $rendertime; /* CPU load during known clock time */ // Format for display or logging (Uncomment as needed for logging) //$cpuUTime = number_format($cpuUTime, 3); // User cpu //$cpuSTime = number_format($cpuSTime, 3); // System cpu //$cpuTot = number_format($cpuTot, 3); // Total (User+System) $cpuStart = number_format($cpuStart, 3); // Startup time (i.e. CPU used before class2.php) $cpuTime = number_format($cpuTime, 3); // CPU while we were measuring the clock (cpuTot-cpuStart) $cpuPct = number_format($cpuPct, 0); // CPU Load (CPU/Clock) } // // Here's a good place to log CPU usage in case you want graphs and/or your host cares about that // e.g. (on a typical vhosted linux host) // // $logname = "/home/mysite/public_html/queryspeed.log"; // $logfp = fopen($logname, 'a+'); fwrite($logfp, "$cpuTot,$cpuPct,$cpuStart,$rendertime,$db_time\n"); fclose($logfp); if ($pref['displayrendertime']) { $rinfo .= CORE_LAN11; if (isset($cpuTime)) { // $rinfo .= "{$cpuTime} cpu sec ({$cpuPct}% load, {$cpuStart} startup). Clock: "; $rinfo .= sprintf(CORE_LAN14, $cpuTime, $cpuPct, $cpuStart); } $rinfo .= $rendertime.CORE_LAN12.$dbPercent.CORE_LAN13.' '; } if ($pref['displaysql']) { $rinfo .= CORE_LAN15.$queryCount.". "; } if (isset($pref['display_memory_usage']) && $pref['display_memory_usage']) { $rinfo .= CORE_LAN16.$memuse; } if (isset($pref['displaycacheinfo']) && $pref['displaycacheinfo']) { $rinfo .= $cachestring."."; } if ($pref['log_page_accesses']) { // Need to log the page info to a text file as CSV data $logname = e_LOG."logd_".date("Y-m-d", time()).".csv"; $logHeader = "Unix time,Date/Time,IP,URL,RenderTime,DbTime,Qrys,Memory-Usage,User-Agent,Request-Method"; $logfp = fopen($logname, 'a+'); if(filesize($logname) == 0 || !is_file($logname)) { fwrite($logfp, $logHeader."\n"); } fwrite($logfp, $logLine."\n"); fclose($logfp); } if (function_exists('theme_renderinfo')) { theme_renderinfo($rinfo); } else { echo($rinfo ? "\n
\n" : ""); } } // End of regular-page footer (the above NOT done for popups) // // C Dump all debug and traffic information // if ((ADMIN || $pref['developer']) && E107_DEBUG_LEVEL) { global $db_debug; echo "\n\nID | SQL Queries | \n
{$c} | {$infovalue} | \n