From 1661c1a1e7bbac1cc259b7e6f83f61c285dc2e0a Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Fri, 23 Apr 2021 19:47:43 +0000 Subject: [PATCH] Bootstrap/Load: Add Function for reliable timing data Adds timer_float which can be used to get the time elapsed so far during the PHP script. Should make it easier to display the page generation time in the footer of admin. WordPress should expose timing data as a float in the most accurate manner possible. timer_stop() has two problems: it uses an initial timestamp generated later than it needs to be and its formatted return value can not reliably be used as a number (some locales swap commas and periods, for example). Props andy, matt, jorbin. Fixes #39163. git-svn-id: https://develop.svn.wordpress.org/trunk@50786 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/load.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index be5a8fcda7..0ea926c9dd 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -333,6 +333,19 @@ function wp_is_maintenance_mode() { return true; } +/** + * Get the time elapsed so far during this PHP script. + * + * Uses REQUEST_TIME_FLOAT that appeared in PHP 5.4.0. + * + * @since 5.8.0 + * + * @return float Seconds since the PHP script started. + */ +function timer_float() { + return microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT']; +} + /** * Start the WordPress micro-timer. *