Make WordPress Core


Ignore:
Timestamp:
04/23/2021 07:47:43 PM (3 years ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r50407 r50786  
    332332
    333333    return true;
     334}
     335
     336/**
     337 * Get the time elapsed so far during this PHP script.
     338 *
     339 * Uses REQUEST_TIME_FLOAT that appeared in PHP 5.4.0.
     340 *
     341 * @since 5.8.0
     342 *
     343 * @return float Seconds since the PHP script started.
     344 */
     345function timer_float() {
     346    return microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'];
    334347}
    335348
Note: See TracChangeset for help on using the changeset viewer.