Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make Server-Timing header output more robust
  • Loading branch information
swissspidy authored May 30, 2023
commit 4e83589ce0e0415f62ddd42c60730e614be7b37b
13 changes: 4 additions & 9 deletions server-timing/class-perflab-server-timing.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,11 @@ public function on_template_include( $passthrough = null ) {
return $passthrough;
}

ob_start();
add_action(
'shutdown',
function() {
$output = ob_get_clean();
ob_start(
function( $output ) {
$this->send_header();
echo $output;
},
// phpcs:ignore PHPCompatibility.Constants.NewConstants
defined( 'PHP_INT_MIN' ) ? PHP_INT_MIN : -1000
Comment on lines -238 to -239
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why this action was configured to run early. Wouldn't it be better to run as late as possible?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is run early based on the idea that the template output was already completed when shutdown runs. If shutdown did a bunch of other things (extremely unlikely but possible), then it would inflate the time in the wp-template metric.

return $output;
}
);
return $passthrough;
}
Expand Down