PHP Caching with APC and WP-Cache


Greg Szorc recently pointed me to this excellent PHP optimization tutorial presented at OSCON 2006 by Rasmus Lerdorf. In the tutorial, he shows how to build a website with some basic SQL calls that handles over 1100 requests/sec using optimization techniques. One of the optimizations he uses is an opcode cacher for PHP called APC. In gentoo, to get this optimization working required a simple emerge dev-php5/pecl-apc. Mr. Lerdorf then goes on to use http_load and callgrind to demonstrate the performance of the website and isolate problem sections.

The performance this PHP cacher provides is by far the best I have seen. I enabled it on this site and the pages are loading lightning fast. I did run into some problems. WP-Cache, an excellent page output caching module for WordPress, and APC don’t play well together. They caused a “White Page of Death” - that is, the first time I loaded a webpage, the page returns blank. Subsequent requests return the desired page, but this is hardly ideal.

Mark Jaquith documented this “white page of death” problem that occurs between the interaction of APC and WP-Cache. His solution, to filter out apc caching wp-cache’d pages, has not seemed to work for me yet. As of right now, I have disabled wp-cache because the performance benefits of APC outweighed those of WP-Cache.

Hopefully, one day, these two excellent solutions will live in harmony. I will continue to try to get them to co-exist as Mr. Jaquith has done. Currently, I have tried setting apc.filters=”-.*cache.*\.php” and apc.filters=”wp-cache-config”. I have tried every possible permutation of flushing the cache and restarting apache. No luck yet.

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
New Phi Kappa Theta website
Destination: India

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

The reason you get the white page is that errors are suppressed in the WP-Cache2 plugin (although you could also suppress them in php.ini). What you can do is remove all those silencing “@” symbols, and see what error is killing you… that might help you find out a solution. The other thing to do is to make sure that your php.ini settings for apc.filters are actually being followed.

Mark, if it were that simple. I’ve done that myself and it’s still not working. I get the exact same error as above. First instance of the page is blank, but every instance after works.

I have removed every single error suppressor from the wp-cache files and it is still causing the error.

[...] Anyway, it appeared other people have been having problems with getting these two bloody beasts to work together, too. So, I decided to take the task on myself to figure out just why these two are having temper-tantrum, even after adding the suggested fix by Mark Jaquith. [...]

Solution has been discovered! I have posted the solution on my blog for details, but so you know I’m not link spammin ya, here’s how: Edit wp-cache-phase2 list 219. Change ob_end_clean() ob_end_flush().

The problem is ob_end_clean() cleans out the buffer without actually flushing it to the screen and I don’t see any flush() calls before hand. Changing it to ob_end_flush() will end the output buffer and flush all data to standard out.

I have tested this solution with and without APC and it seems to be working.