option to log slow pages

This commit is contained in:
Shish 2019-05-26 10:41:24 +01:00
parent 6175b36cc9
commit f4c18930ce
3 changed files with 14 additions and 0 deletions

View file

@ -41,6 +41,7 @@ _d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,set
_d("EXTRA_EXTS", ""); // string optional extra extensions
_d("BASE_URL", null); // string force a specific base URL (default is auto-detect)
_d("MIN_PHP_VERSION", '7.0');// string minimum supported PHP version
_d("SLOW_PAGES", null); // float log pages which take more time than this
_d("ENABLED_MODS", "imageboard");
/*

View file

@ -350,6 +350,18 @@ function get_debug_info(): string {
return $debug;
}
function log_slow() {
global $_shm_load_start;
if(!is_null(SLOW_PAGES)) {
$_time = microtime(true) - $_shm_load_start;
if($_time > SLOW_PAGES) {
$_query = _get_query();
$_dbg = get_debug_info();
file_put_contents("data/slow-pages.log", "$_time $_query $_dbg\n", FILE_APPEND | LOCK_EX);
}
}
}
function score_assert_handler($file, $line, $code, $desc = null) {
$file = basename($file);
print("Assertion failed at $file:$line: $code ($desc)");

View file

@ -107,4 +107,5 @@ catch(Exception $e) {
_fatal_error($e);
$_shm_ctx->log_ender();
}
log_slow();