Measure and log feed render time
Pairing benecaster_feed_before_render with benecaster_feed_after_render gives you the real render duration for a feed request. Useful when you suspect feed generation is slow but want evidence rather than a hunch.
What you are measuring is the compile-and-echo step only — the before hook fires after the request is validated and headers are sent. A cache hit therefore measures near zero, which is the point: a log full of near-zero timings with occasional spikes tells you the cache is working and the spikes are cache misses.
Log selectively. Feeds are polled constantly by podcast apps, so an unconditional log line per request will bury your error log. The threshold below writes only the slow ones — and it is the difference between a useful signal and a file nobody can read.
Wire the result to your observability platform rather than error_log() if you have one; the shape of the measurement is the same either way.
Code
<?php
add_action(
'benecaster_feed_before_render',
function ( int $show_id, string $tier_slug ): void {
$GLOBALS['my_feed_render_start'] = microtime( true );
},
10,
2
);
add_action(
'benecaster_feed_after_render',
function ( int $show_id, string $tier_slug, string $xml ): void {
if ( empty( $GLOBALS['my_feed_render_start'] ) ) {
return;
}
$ms = ( microtime( true ) - $GLOBALS['my_feed_render_start'] ) * 1000;
unset( $GLOBALS['my_feed_render_start'] );
// Only record the slow ones - feeds are polled far too often to log every request.
if ( $ms < 250 ) {
return;
}
error_log(
sprintf(
'[benecaster] slow feed render: show=%d tier=%s %.1fms %dKB',
$show_id,
$tier_slug !== '' ? $tier_slug : 'public',
$ms,
(int) ( strlen( $xml ) / 1024 )
)
);
},
10,
3
);
Hooks Used
Need this built rather than just documented? See our services →