Created
March 8, 2024 01:06
-
-
Save felixarntz/887aa45829709991f4ecd114ae52ed14 to your computer and use it in GitHub Desktop.
wp-server-timing-quick-hack-template.php (using Performance Lab Server-Timing API)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_func() { | |
global $some_metric_global; | |
if ( ! isset( $some_metric_global ) ) { | |
$some_metric_global = 0.0; | |
add_action( | |
'wp_footer', | |
function() { | |
perflab_server_timing_register_metric( | |
'some_metric_global', | |
array( | |
'measure_callback' => function ( $metric ) { | |
global $some_metric_global; | |
$metric->set_value( $some_metric_global * 1000.0 ); | |
}, | |
'access_cap' => 'exist', | |
) | |
); | |
} | |
); | |
} | |
$start = microtime( true ); | |
// More logic... | |
$some_metric_global += microtime( true ) - $start; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment