After upgrading to WP 2.1, Kelson had to downgrade WP-Cache 2.1 to a tweaked 2.0.17, because with RSS feeds WP-Cache 2.1 would, when serving a request from its cache, always return Content-Type text/html instead of Content-Type text/xml.
Why does WP-Cache not reproduce the original Content-Type text/xml?
I had a look at wp_cache_shutdown_callback within wp-cache-phase2.php and found that all and everything should work perfectly.
Disabling WP-Cache’s code that forcibly sends a Content-Type text/html header if there is none, led me to the mazes ob flush(), ob_flush(), ob_end_flush(), headers_sent() and the like. And to the interesting fact, that…
WP-Cache does not see at least some of the http response headers, that have been output by WordPress code. Why?
If WP-Cache misses some headers, the reason must be located somewhere in the way it tries to retrieve them. wp_cache_get_response_headers() first interrogates apache_response_headers() and, if this function does not exist, reverts to headers_list().
headers_list() docs clearly state, that it returns both, headers that have already been sent and those that have not yet been sent, i.e. are about to be sent. That might be the ones, that WP-Cache is missing after all. headers_list() requires PHP >= 5, but even then, headers_list() may not work at all due to Bug #29683 headers_list() func. return empty array.
apache_response_headers() requires PHP >= 4.3 (>= 4.3.3 with NSAPI) and its docs are a little bit vague on platform requirements. There are some hints on how to have it “working good”.
- For apache_response_headers() working good, you need to set up output_buffering = Off in php.ini. Ok, I’ve checken on that one, it’s still set to its default = off.
- If apache_response_headers() returns an empty array, try calling flush() before and it’ll get filled. Bingo 🙂 At least on my system using the Vistered Little Theme. Strange though, that it was just the Content-Type header, that was missing, the other ones were included even without the flush()…
Fix for wp_cache_get_response_headers within wp-cache-phase2.php:
function wp_cache_get_response_headers() {
if(function_exists('apache_response_headers')) {
flush(); // fix text/html on feeds
$headers = apache_response_headers();
} else if(function_exists('headers_list')) {
$headers = array();
foreach(headers_list() as $hdr) {
list($header_name, $header_value) = explode(': ', $hdr, 2);
$headers[$header_name] = $header_value;
}
} else
$headers = null;
return $headers;
}
Last-not-least an honorable mention of ieHTTPHeaders , that made it possible to spy on both the actual http request and response headers and much more. Thanks to Jonas!
There’s another interesting area as to when a page needs refreshing. It’s the If-Modified-Since header. Do WordPress and WP-Cache support this technique, and why not? I’ll try to cope with that one in a future post…
It’s going to be end of mine day, however before ending I am reading this enormous paragraph
to increase my know-how.
LikeLike
you are really a just right webmaster. The website loading speed is amazing.
It kind of feels that you are doing any distinctive trick.
Also, The contents are masterpiece. you’ve performed a fantastic job in this matter!
LikeLike
Thanks a lot!
But… I’m not the culprit – it’s all done by http://wordpress.com‘s magic – out-of-the-box 🙂
Regards,
Reiner
LikeLike