num_queries; $header_values = array(); foreach ( $server_timing_values as $slug => $value ) { if ( is_float( $value ) ) { $value = round( $value * 1000.0, 2 ); } $header_values[] = sprintf( '%1$s;dur=%2$s', $slug, $value ); } header( 'Server-Timing: ' . implode( ', ', $header_values ) ); return $output; } ); return $template; }, PHP_INT_MAX ); add_action( 'admin_init', static function () { global $timestart, $wpdb; ob_start( static function ( $output ) use ( $wpdb, $timestart ) { $server_timing_values = array(); $server_timing_values['wpTotal'] = microtime( true ) - $timestart; /* * While values passed via Server-Timing are intended to be durations, * any numeric value can actually be passed. * This is a nice little trick as it allows to easily get this information in JS. */ $server_timing_values['wpMemoryUsage'] = memory_get_usage(); $server_timing_values['wpDbQueries'] = $wpdb->num_queries; $header_values = array(); foreach ( $server_timing_values as $slug => $value ) { if ( is_float( $value ) ) { $value = round( $value * 1000.0, 2 ); } $header_values[] = sprintf( '%1$s;dur=%2$s', $slug, $value ); } header( 'Server-Timing: ' . implode( ', ', $header_values ) ); return $output; } ); }, PHP_INT_MAX );