Troubleshooting & How-Tos 📡 🔍 Obsolete

PHP5 and WP Cache 2

After upgrading to PHP5, something in my WordPress setup disagrees with the combination of PHP 5 and WP-Cache 2. Pages were turning up blank the first time they were loaded, then perfectly OK the second time. Oddly, it was working fine under PHP 4.4, MySQL 5, and WordPress 2.

I tried the suggestion in comment 295 on the WP-Cache post (link broken): in wp-cache-phase2.php, in the function wp_cache_ob_end(), change ob_end_clean() to ob_end_flush().

It fixed the blanking problem, but it broke Content-Type headers on feeds. Everything was getting sent as text/html, even when I told it not to cache the feed files.

Apparently the function WP-Cache uses to save the original HTTP headers (including Content-Type) doesn’t always pick up data if you’re using output buffering—which of course is integral to WP-Cache. The suggested solution is to flush the buffer before calling apache_response_headers(), so I looked at the code. ob_end_flush() is called right after the block that saves the headers, and the only circumstance in which it tries to write any output is if there isn’t already a Content-Type or Last-Modified header. Well, PHP is going to add a default Content-Type in the worst case, and I’m pretty sure WP generates Last-Modified everywhere.

So I moved that ob_end_flush() to just before the line with if(function_exists('apache_response_headers') ). It seems to work so far. It’s caching, it’s not pushing out blank pages, and it’s sending the correct content type on feeds.