- Timestamp:
- 05/02/2024 01:57:49 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/performance/wp-content/mu-plugins/server-timing.php
r57083 r58076 5 5 static function ( $template ) { 6 6 7 global $timestart ;7 global $timestart, $wpdb; 8 8 9 9 $server_timing_values = array(); … … 16 16 add_action( 17 17 'shutdown', 18 static function () use ( $server_timing_values, $template_start ) { 19 20 global $timestart; 21 18 static function () use ( $server_timing_values, $template_start, $wpdb ) { 22 19 $output = ob_get_clean(); 23 20 … … 31 28 * This is a nice little trick as it allows to easily get this information in JS. 32 29 */ 33 $server_timing_values['memory-usage'] = memory_get_usage(); 30 $server_timing_values['memory-usage'] = memory_get_usage(); 31 $server_timing_values['db-queries'] = $wpdb->num_queries; 32 $server_timing_values['ext-obj-cache'] = wp_using_ext_object_cache() ? 1 : 0; 34 33 35 34 $header_values = array(); … … 51 50 PHP_INT_MAX 52 51 ); 52 53 add_action( 54 'admin_init', 55 static function () { 56 global $timestart, $wpdb; 57 58 ob_start(); 59 60 add_action( 61 'shutdown', 62 static function () use ( $wpdb, $timestart ) { 63 $output = ob_get_clean(); 64 65 $server_timing_values = array(); 66 67 $server_timing_values['total'] = microtime( true ) - $timestart; 68 69 /* 70 * While values passed via Server-Timing are intended to be durations, 71 * any numeric value can actually be passed. 72 * This is a nice little trick as it allows to easily get this information in JS. 73 */ 74 $server_timing_values['memory-usage'] = memory_get_usage(); 75 $server_timing_values['db-queries'] = $wpdb->num_queries; 76 $server_timing_values['ext-obj-cache'] = wp_using_ext_object_cache() ? 1 : 0; 77 78 $header_values = array(); 79 foreach ( $server_timing_values as $slug => $value ) { 80 if ( is_float( $value ) ) { 81 $value = round( $value * 1000.0, 2 ); 82 } 83 $header_values[] = sprintf( 'wp-%1$s;dur=%2$s', $slug, $value ); 84 } 85 header( 'Server-Timing: ' . implode( ', ', $header_values ) ); 86 87 echo $output; 88 }, 89 PHP_INT_MIN 90 ); 91 }, 92 PHP_INT_MAX 93 );
Note: See TracChangeset
for help on using the changeset viewer.