Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $output->getFormatter()->setStyle('fail', new OutputFormatterStyle('red'));
     $output->getFormatter()->setStyle('pass', new OutputFormatterStyle('green'));
     if ($this->runTests(1) === false || $this->runTests(2) === false) {
         return 1;
     }
     $normalized = $this->normalizeData($this->loadInputData());
     $startTime = microtime(true);
     $result = $this->perform($normalized);
     $stopTime = microtime(true);
     $output->writeln('');
     $output->writeln('Answer for <comment>Step #1</comment>: <pass>' . $result[0] . '</pass>');
     $output->writeln('Answer for <comment>Step #2</comment>: <pass>' . $result[1] . '</pass>');
     $output->writeln('');
     $output->writeln('Total execution time: <pass>' . round($stopTime - $startTime, 2) . 's</pass>');
     $output->writeln('Total memory usage: <pass>' . get_memory_usage() . '</pass>');
 }
Exemplo n.º 2
0
 /**
  * Output the page footer.
  */
 function output_footer($quit = true)
 {
     global $mybb, $maintimer, $db, $lang, $plugins;
     $plugins->run_hooks("admin_page_output_footer");
     $memory_usage = get_friendly_size(get_memory_usage());
     $totaltime = $maintimer->stop();
     $querycount = $db->query_count;
     echo "\t\t\t</div>\n";
     echo "\t\t</div>\n";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t</div>\n";
     echo "<div id=\"footer\"><p class=\"generation\">" . $lang->sprintf($lang->generated_in, $totaltime, $querycount, $memory_usage) . "</p><p class=\"powered\">Powered By MyBB. &copy; " . COPY_YEAR . " MyBB Group. All Rights Reserved.</p></div>\n";
     if ($mybb->debug_mode) {
         echo $db->explain;
     }
     echo "</div>\n";
     echo "</body>\n";
     echo "</html>\n";
     if ($quit != false) {
         exit;
     }
 }
Exemplo n.º 3
0
    foreach ($_REQUEST as $var_name => $value) {
        unset(${$var_name});
    }
}
define('SITE_ROOT', str_replace('\\', '/', dirname(getenv('SCRIPT_FILENAME'))));
if (!defined('SITE_FILE_ROOT')) {
    define('SITE_FILE_ROOT', SITE_ROOT . '/');
}
if (!extension_loaded('mbstring')) {
    require_once SITE_FILE_ROOT . 'includes/compatiblity/mbstring.php';
}
mb_internal_encoding('UTF-8');
/* mb_http_output('UTF-8'); */
$starttime = explode(' ', microtime());
$starttime = $starttime[1] + $starttime[0];
$base_memory_usage = get_memory_usage();
/* REQUEST_URI not set in IIS */
if (empty($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
    if ($_SERVER['QUERY_STRING']) {
        $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
}
require_once SITE_FILE_ROOT . 'includes/display/template.php';
require_once SITE_FILE_ROOT . 'includes/functions.php';
require_once SITE_FILE_ROOT . 'includes/handler.php';
require_once SITE_FILE_ROOT . 'config.php';
@register_shutdown_function('script_close');
/* 
	Load First Set of Classes
*/
Exemplo n.º 4
0
/**
 * Prints a debug information page
 */
function debug_page()
{
    global $db, $debug, $templates, $templatelist, $mybb, $maintimer, $globaltime, $ptimer, $parsetime, $lang;
    $totaltime = $maintimer->totaltime;
    $phptime = $maintimer->format($maintimer->totaltime - $db->query_time);
    $query_time = $maintimer->format($db->query_time);
    $percentphp = number_format($phptime / $maintimer->totaltime * 100, 2);
    $percentsql = number_format($query_time / $maintimer->totaltime * 100, 2);
    $phpversion = PHP_VERSION;
    $serverload = get_server_load();
    if ($mybb->settings['gzipoutput'] != 0) {
        $gzipen = "Enabled";
    } else {
        $gzipen = "Disabled";
    }
    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
    echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
    echo "<head>";
    echo "<title>MyBB Debug Information</title>";
    echo "</head>";
    echo "<body>";
    echo "<h1>MyBB Debug Information</h1>\n";
    echo "<h2>Page Generation</h2>\n";
    echo "<table bgcolor=\"#666666\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#CCCCCC\" colspan=\"4\"><b><span style=\"size:2;\">Page Generation Statistics</span></b></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Page Generation Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$totaltime} seconds</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">No. DB Queries:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$db->query_count}</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">PHP Processing Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$phptime} seconds ({$percentphp}%)</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">DB Processing Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$query_time} seconds ({$percentsql}%)</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Extensions Used:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$mybb->config['database']['type']}, xml</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Global.php Processing Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$globaltime} seconds</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">PHP Version:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$phpversion}</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Server Load:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$serverload}</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">GZip Encoding Status:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$gzipen}</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">No. Templates Used:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">" . count($templates->cache) . " (" . intval(count(explode(",", $templatelist))) . " Cached / " . intval(count($templates->uncached_templates)) . " Manually Loaded)</font></td>\n";
    echo "</tr>\n";
    $memory_usage = get_memory_usage();
    if (!$memory_usage) {
        $memory_usage = $lang->unknown;
    } else {
        $memory_usage = get_friendly_size($memory_usage) . " ({$memory_usage} bytes)";
    }
    $memory_limit = @ini_get("memory_limit");
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Usage:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_usage}</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Limit:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_limit}</font></td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    echo "<h2>Database Connections (" . count($db->connections) . " Total) </h2>\n";
    echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
    echo "<tr>\n";
    echo "<td style=\"background: #fff;\">" . implode("<br />", $db->connections) . "</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    echo "<br />\n";
    echo "<h2>Database Queries (" . $db->query_count . " Total) </h2>\n";
    echo $db->explain;
    echo "<h2>Template Statistics</h2>\n";
    if (count($templates->cache) > 0) {
        echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
        echo "<tr>\n";
        echo "<td style=\"background-color: #ccc;\"><strong>Templates Used (Loaded for this Page) - " . count($templates->cache) . " Total</strong></td>\n";
        echo "</tr>\n";
        echo "<tr>\n";
        echo "<td style=\"background: #fff;\">" . implode(", ", array_keys($templates->cache)) . "</td>\n";
        echo "</tr>\n";
        echo "</table>\n";
        echo "<br />\n";
    }
    if (count($templates->uncached_templates) > 0) {
        echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
        echo "<tr>\n";
        echo "<td style=\"background-color: #ccc;\"><strong>Templates Requiring Additional Calls (Not Cached at Startup) - " . count($templates->uncached_templates) . " Total</strong></td>\n";
        echo "</tr>\n";
        echo "<tr>\n";
        echo "<td style=\"background: #fff;\">" . implode(", ", $templates->uncached_templates) . "</td>\n";
        echo "</tr>\n";
        echo "</table>\n";
        echo "<br />\n";
    }
    echo "</body>";
    echo "</html>";
    exit;
}
Exemplo n.º 5
0
 /**
  * Output the page footer.
  *
  * @param bool $quit
  */
 function output_footer($quit = true)
 {
     global $mybb, $maintimer, $db, $lang, $plugins;
     $args = array('this' => &$this, 'quit' => &$quit);
     $plugins->run_hooks("admin_page_output_footer", $args);
     $memory_usage = get_friendly_size(get_memory_usage());
     $totaltime = format_time_duration($maintimer->stop());
     $querycount = $db->query_count;
     if (my_strpos(getenv("REQUEST_URI"), "?")) {
         $debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "&amp;debug=1#footer";
     } else {
         $debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "?debug=1#footer";
     }
     echo "\t\t\t</div>\n";
     echo "\t\t</div>\n";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t</div>\n";
     echo "<div id=\"footer\"><p class=\"generation\">" . $lang->sprintf($lang->generated_in, $totaltime, $debuglink, $querycount, $memory_usage) . "</p><p class=\"powered\">Powered By <a href=\"http://www.mybb.com/\" target=\"_blank\">MyBB</a>, &copy; 2002-" . COPY_YEAR . " <a href=\"http://www.mybb.com/\" target=\"_blank\">MyBB Group</a>.</p></div>\n";
     if ($mybb->debug_mode) {
         echo $db->explain;
     }
     echo "</div>\n";
     echo "</body>\n";
     echo "</html>\n";
     if ($quit != false) {
         exit;
     }
 }
Exemplo n.º 6
0
 function footer_debug()
 {
     global $_CORE_CONFIG, $_CLASS, $starttime;
     $mtime = explode(' ', microtime());
     $totaltime = $mtime[0] + $mtime[1] - $starttime - $_CLASS['core_db']->queries_time;
     $debug_output = 'Code Time : ' . round($totaltime, 4) . 's | Queries Time ' . round($_CLASS['core_db']->queries_time, 4) . 's | ' . $_CLASS['core_db']->num_queries . ' Queries  ] <br /> [ GZIP : ' . (in_array('ob_gzhandler', ob_list_handlers()) ? 'On' : 'Off') . ' | Load : ' . ($_CLASS['core_user']->load ? $_CLASS['core_user']->load : 'N/A');
     if ($memory_usage = get_memory_usage()) {
         global $base_memory_usage;
         $memory_usage -= $base_memory_usage;
         $memory_usage = $memory_usage >= 1048576 ? round(round($memory_usage / 1048576 * 100) / 100, 2) . ' ' . $_CLASS['core_user']->lang['MB'] : ($memory_usage >= 1024 ? round(round($memory_usage / 1024 * 100) / 100, 2) . ' ' . $_CLASS['core_user']->lang['KB'] : $memory_usage . ' ' . $_CLASS['core_user']->lang['BYTES']);
         $debug_output .= ' | Memory Usage: ' . $memory_usage;
     }
     return $debug_output;
 }
Exemplo n.º 7
0
/**
 * Checks and Attempts to allocate more memory if needed
 *
 * @return boolean true on success, false on failure
**/
function check_memory()
{
    $memory_usage = get_memory_usage();
    if (!$memory_usage) {
        return false;
    }
    $memory_limit = @ini_get("memory_limit");
    if (!$memory_limit || $memory_limit == -1) {
        return false;
    }
    $limit = preg_match("#^([0-9]+)\\s?([kmg])b?\$#i", trim(my_strtolower($memory_limit)), $matches);
    $memory_limit = 0;
    if ($matches[1] && $matches[2]) {
        switch ($matches[2]) {
            case "k":
                $memory_limit = $matches[1] * 1024;
                break;
            case "m":
                $memory_limit = $matches[1] * 1048576;
                break;
            case "g":
                $memory_limit = $matches[1] * 1073741824;
        }
    }
    $current_usage = get_memory_usage();
    $free_memory = $memory_limit - $current_usage;
    // Do we have less then 2 MB's left?
    if ($free_memory < 2097152) {
        if ($matches[1] && $matches[2]) {
            switch ($matches[2]) {
                case "k":
                    $memory_limit = ($memory_limit + 2097152) / 1024 . "K";
                    break;
                case "m":
                    $memory_limit = ($memory_limit + 2097152) / 1048576 . "M";
                    break;
                case "g":
                    $memory_limit = ($memory_limit + 2097152) / 1073741824 . "G";
            }
        }
        @ini_set("memory_limit", $memory_limit);
    }
}
Exemplo n.º 8
0
 public function __destruct()
 {
     global $start_timer, $load_timer, $db;
     $load_time = $start_timer - $load_timer;
     $end_timer = microtime(true);
     $total_time = $end_timer - $start_timer;
     $php_time = number_format($total_time - $db->query_time, 7);
     $query_time = number_format($db->query_time, 7);
     if ($total_time > 0) {
         $percentphp = number_format($php_time / $total_time * 100, 2);
         $percentsql = number_format($query_time / $total_time * 100, 2);
     } else {
         // if we've got a super fast script...  all we can do is assume something
         $percentphp = 0;
         $percentsql = 0;
     }
     $phpversion = PHP_VERSION;
     $serverload = get_server_load();
     $current_memory_usage = get_memory_usage();
     if ($current_memory_usage) {
         $memory_usage = " / Memory Usage: " . get_friendly_size($current_memory_usage);
     } else {
         $memory_usage = '';
     }
     $this->trace0("Generated in {$total_time} seconds ({$percentphp}% PHP / {$percentsql}% MySQL) / Initialize Load Time: {$load_time} / SQL Queries: {$db->query_count}{$memory_usage} PHP version: {$phpversion} / Server Load: {$serverload}");
 }