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.


Built from https://develop.svn.wordpress.org/trunk@50786


git-svn-id: http://core.svn.wordpress.org/trunk@50395 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2021-04-23 19:49:05 +00:00
parent 75d7c7e8d9
commit 926cd0afee
2 changed files with 14 additions and 1 deletions

View File

@ -333,6 +333,19 @@ function wp_is_maintenance_mode() {
return true; 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. * Start the WordPress micro-timer.
* *

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.8-alpha-50785'; $wp_version = '5.8-alpha-50786';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.