$long_request_log_level = false; if ($bot && $bot_long_request_level) { $long_request_log_level = $bot_long_request_level; } elseif (!$bot && $human_long_request_level) { $long_request_log_level = $human_long_request_level; } if (!$long_request_log_level) { return; } // If request is too slow if ($duration > $long_request_log_level) { // We store it $long_request_log = new CLongRequestLog(); $long_request_log->datetime = CMbDT::format(null, "%Y-%m-%d %H:%M:00"); $long_request_log->duration = $duration; $long_request_log->server_addr = get_server_var('SERVER_ADDR'); $long_request_log->user_id = CAppUI::$user->_id; // GET and POST params $long_request_log->_query_params_get = $_GET; $long_request_log->_query_params_post = $_POST; $session = $_SESSION; unset($session['AppUI']); unset($session['dPcompteRendu']['templateManager']); // SESSION params $long_request_log->_session_data = $session; // Unique Request ID $long_request_log->requestUID = CApp::getRequestUID(); if ($msg = $long_request_log->store()) { trigger_error($msg, E_USER_WARNING); } }
/** * Write HTTP header containing profiling data * * @return void */ static function writeHeader() { if (!self::isProfiling()) { return; } if (headers_sent()) { return; } global $m, $action, $dosql; $req = "{$m}|" . (empty($dosql) ? $action : $dosql); header("X-Mb-Timing: " . json_encode(self::out())); header("X-Mb-Req: {$req}"); header("X-Mb-RequestUID: " . CApp::getRequestUID()); }
/** * Custom exception handler with backtrace * * @param exception $exception Thrown exception * * @return void */ function exceptionHandler($exception) { global $dPconfig; $time = date("Y-m-d H:i:s"); // User information $user_id = null; $user_view = ""; if (class_exists("CAppUI", false) && CAppUI::$user) { $user = CAppUI::$user; if ($user->_id) { $user_id = $user->_id; $user_view = $user->_view; } } // Server IP $server_ip = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : null; $file = mbRelativePath($exception->getFile()); $line = $exception->getLine(); $type = "exception"; $text = $exception->getMessage(); // Stacktrace $contexts = $exception->getTrace(); foreach ($contexts as &$ctx) { unset($ctx['args']); } // Might noy be ready at the time error is thrown $session = isset($_SESSION) ? $_SESSION : array(); unset($session['AppUI']); unset($session['dPcompteRendu']['templateManager']); $_all_params = array("GET" => $_GET, "POST" => $_POST, "SESSION" => $session); filterInput($_all_params); // CApp might not be ready yet as of early error handling $request_uid = null; if (class_exists("CApp", false)) { $request_uid = CApp::getRequestUID(); CApp::$performance[CError::$_categories["exception"]]++; } $build_output = ini_get("display_errors"); $save_to_file = false; $data = array("stacktrace" => $contexts, "param_GET" => $_all_params["GET"], "param_POST" => $_all_params["POST"], "session_data" => $_all_params["SESSION"]); if (@$dPconfig["error_logs_in_db"] && class_exists("CErrorLog")) { try { CErrorLog::insert($user_id, $server_ip, $time, $request_uid, $type, $text, $file, $line, $data); } catch (Exception $e) { $build_output = true; $save_to_file = true; } } else { $build_output = true; $save_to_file = true; } if ($build_output) { $hash = md5(serialize($contexts)); $html_class = "big-warning"; $log = "\n\n<div class='{$html_class}' title='{$hash}'>"; if ($user_id) { $log .= "\n<strong>User: </strong>{$user_view} ({$user_id})"; } $file = CError::openInIDE($file, $line); $log .= <<<HTML <strong>Time: </strong>{$time} <strong>Type: </strong>{$type} <strong>Text: </strong>{$text} <strong>File: </strong>{$file} <strong>Line: </strong>{$line} HTML; foreach ($_all_params as $_type => $_params) { $log .= print_infos($_all_params[$_type], $_type); } foreach ($contexts as $context) { $function = isset($context["class"]) ? $context["class"] . ":" : ""; $function .= $context["function"] . "()"; $log .= "\n<strong>Function: </strong> {$function}"; if (isset($context["file"])) { $log .= "\n<strong>File: </strong>" . CError::openInIDE($context["file"], isset($context["line"]) ? $context["line"] : null); } if (isset($context["line"])) { $log .= "\n<strong>Line: </strong>" . $context["line"]; } $log .= "<br />"; } $log .= "</div>"; if ($save_to_file) { file_put_contents(LOG_PATH, $log, FILE_APPEND); } if (ini_get("display_errors")) { echo $log; } } }