Пример #1
0
 public function build()
 {
     $this->setLayout('debug/debug.tpl');
     // Basic Debug data:
     $debug['controllers'] = \Sifo\Debug::get('controllers');
     $debug['benchmarks'] = \Sifo\Debug::get('benchmarks');
     $debug['elements'] = \Sifo\Debug::get('elements');
     $debug['times'] = \Sifo\Debug::get('times');
     $this->renderDebugModule($debug, 'basic_debug', 'debug/basic_debug.tpl');
     // Database debug.
     $debug['queries'] = \Sifo\Debug::get('queries');
     $debug['queries_errors'] = \Sifo\Debug::get('queries_errors');
     $debug['queries_duplicated'] = \Sifo\Debug::get('duplicated_queries');
     $this->assign('debug', $debug);
     $this->renderDebugModule($debug, 'database', 'debug/database.tpl');
     // Search debug.
     $debug['searches'] = \Sifo\Debug::get('searches');
     $this->assign('debug', $debug);
     $this->renderDebugModule($debug, 'search', 'debug/search.tpl');
     // Environment variables:
     $debug['session'] = $this->getSessionData();
     $debug['cookies'] = FilterCookieDebug::getCookiesArray();
     // Debug messages:
     $debug['log_messages'] = \Sifo\Debug::get('log_messages');
     $this->assign('log_messages', $debug['log_messages']);
     $this->renderDebugModule($debug, 'log_messages', 'debug/log_messages.tpl');
     // Summary debug:
     $debug['rebuild_all'] = $this->isRebuildAllActive();
     $debug['times']['total'] = \Sifo\Benchmark::getInstance()->timingCurrent();
     if (!isset($debug['times']['cache'])) {
         $debug['times']['cache'] = 0;
     }
     if (!isset($debug['times']['external'])) {
         $debug['times']['external'] = 0;
     }
     if (!isset($debug['times']['db_connections'])) {
         $debug['times']['db_connections'] = 0;
     }
     if (!isset($debug['times']['db_queries'])) {
         $debug['times']['db_queries'] = 0;
     }
     if (!isset($debug['times']['search'])) {
         $debug['times']['search'] = 0;
     }
     $debug['times']['scripts'] = $debug['times']['total'] - ($debug['times']['db_connections'] + $debug['times']['db_queries'] + $debug['times']['search'] + $debug['times']['cache'] + $debug['times']['external']);
     $debug['memory_usage'] = $this->getMemoryUsage();
     $this->finalRender($debug);
 }
Пример #2
0
 /**
  * Fills some debug data to be displayed in the debug interface.
  *
  * @param string $statement The sql statement being queried.
  * @param float $query_time The time that the query needed to be completed.
  * @param string $context The context of the sql query.
  * @param integer|array $resultset The result of the query.
  */
 public static function setDebug($statement, $query_time, $context, $resultset, $db_params, $pdo = null)
 {
     if ($resultset !== false) {
         $error = $resultset->errorInfo();
         $resultset_array = $resultset->fetchAll();
         $rows_num = $resultset->rowCount();
     } else {
         $error = $pdo->errorInfo();
         $resultset_array = 0;
         $rows_num = 0;
     }
     $debug_query = array("tag" => $context, "sql" => $statement, "type" => 0 === stripos($statement, 'SELECT') ? 'read' : 'write', "host" => $db_params['db_host'], "database" => $db_params['db_name'], "user" => $db_params['db_user'], "trace" => DebugMysql::generateTrace(debug_backtrace(false)), "resultset" => $resultset_array, "time" => $query_time, "error" => isset($error[2]) !== false ? $error[2] : false);
     $debug_query['rows_num'] = $rows_num;
     if ($debug_query['error'] !== false) {
         // Log mysql_errors to disk:
         file_put_contents(ROOT_PATH . '/logs/errors_database.log', "================================\nDate: " . date('d-m-Y H:i:s') . "\nError:\n" . $error . "\n ", FILE_APPEND);
         Debug::push('queries_errors', $error);
     }
     Debug::push('queries', $debug_query);
 }