diff --git a/core/sys_config.php b/core/sys_config.php index 296885a8..7f07e6db 100644 --- a/core/sys_config.php +++ b/core/sys_config.php @@ -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"); /* diff --git a/core/util.php b/core/util.php index 7129f0f2..09b87dab 100644 --- a/core/util.php +++ b/core/util.php @@ -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)"); diff --git a/index.php b/index.php index e748c06b..7c9ee6b9 100644 --- a/index.php +++ b/index.php @@ -107,4 +107,5 @@ catch(Exception $e) { _fatal_error($e); $_shm_ctx->log_ender(); } +log_slow();