Using WP-Cache on GoDaddy (500 Error)
Published on September 8, 2007
This post has nothing to do with online dating. It has to do with a particular error, 500 Internal Server Error, when using WordPress and the plug-in WP-Cache on a GoDaddy shared server. My hope is that others who experience the issues I had might find this post and (hopefully) will be able to avoid the hassle I went through!
The Problem
WP-Cache is a plug-in for WordPress that allows web pages to be served quicker by requesting data from the database far less often. However, when this plugin is enable on GoDaddy a strange thing occurs: every other time you load the page you get a 500 Internal Server Error. When this occurs, I suspect most WordPress users on GoDaddy simply disable the plug-in. Unfortunately, if their WordPress site starts to generate traffic, GoDaddy will complain that they are creating too much of a load on the database server. So there appears to be a catch-22 in that GoDaddy doesn’t support the technology that would allow its customer to avoid the very problem the company is complaining about.
The Solution
1. Download the wp-cache-phase1.php in /blog_home/wp-content/plugins/wp-cache/ from your web server.
2. Edit the file by finding the lines:
foreach ($meta->headers as $header) {
header($header);
}
3. Replace these lines with the following:
foreach ($meta->headers as $header) {
if (strpos($header, ‘Last-Modified:’)===FALSE) {
header($header);
} else {
// do nothing – makes GoDaddy angry
}
}
4. Upload the wp-cache-phase1.php to your web server and try refreshing some cached pages.
The Warning
As you will discover if you read below, I’m not very confident in what I am doing and I’ve stumbled through most of my testing. Implementing this change, while it may fix wp-cache, may create other problems. It may not, though. I really have no idea. Also, I was having problems with a header for Last-Modified – I have no clue whether others are going to see the same issue. My solution may not be a solution at all. All I can say is that in my opinion, it appears to work. At any rate, use this at your own risk!
The Explanation (From a Novice)
I am absolutely new to WordPress, PHP, Apache, etc. I am a Java developer by profession so I can read the code but I suspect many of the steps I took, which are described below, were an absolute waste of time created by my ignorance. My hopes are that an expert may be able to review this and explain better why the problem occurs (so I’ve included all the steps I’ve taken working on this issue). Also, if you are also a novice and are interested in understanding some of what I discuss, it would be best to review the readme.txt included with the wp-cache plug-in.
When I started reading about WP-Cache I immediately started seeing articles (for example, here and here) regarding problems when using GoDaddy. Depressing me even further: most of the responses I found seemed to simply write-off the problem as an unaddressable GoDaddy issue. Honestly, after seeing so many people state so convincingly that any 500 Internal Server Error is GoDaddy’s problem and nothing can be done to fix it, I was inclined to simply believe that there was no hope.
Regardless, I decided to give the plug-in a try hoping that maybe there was some difference between my GoDaddy server and everyone else’s (heh). The install went well and even the first time I loaded a page I could see it appear in my cache. My excitement lasted about 5 seconds: after a refresh I was viewing the dreaded 500 Internal Server Error. I fooled around with some settings on the plug-in itself but it did no good. Things appeared to be broken. Before giving up, I decided to view the source of the 500 Internal Error page, believing there might be some clue there. To my surprise, the entire code of my page was in the source! In other words, I was not seeing the expected 5 lines of source for the 500 error but rather 100+ lines of the page I actually attempted to load. This was exciting to me because now I could add some debug and try to determine where the problem was occuring.
My first thought was that if the page was loading, the first part of (wp-cache-phase1.php) was working and it must be the caching of the page to disk (wp-cache-phase2.php) where the problem existed. I found the line in wp-cache-phase1.php that called phase2 and commented it:
// wp_cache_phase2();
I reloaded my previously cached page but the problem persisted. This was a good thing, though, as I found the code in phase1 more understandable.
At this point, I started commenting out different sections of the phase1 code. I discovered all my problems disappeared when I commented out the foreach loop that creates the headers. I added logging to this section and found that I had two headers:
- Last-Modified: Sat, 08 Sep 2007 13:31:29 GMT
- Content-Type: text/html; charset=”UTF-8″
Then, instead of using the foreach loop, I manually tried each of the headers individually. Testing Content-Type went fine but testing Last-Modified and the 500 errors reappeared. At this point, I created a new php file to test the Last-Modified header (you can view the source here). I named this test.php and loaded it successfully (you can test it yourself if you would like. When I reloaded it, though, the 500 error occurred! At this point, I read a little on the Last-Modified header and decided to disable the cache on my web browser. Now the problem disappearred no matter how often I reloaded…so the problem seems somehow related to when a browser is deciding if it needs to request to redownload files (I’m out of my league at this point).
The Help?
And now, I am at a loss. I can implement wp-cache but only if I explicitly ignore Last-Modified headers. Will this create problems? According to this document, I should always send Last-Modified when able. I restored the old code to view the headers when the page displays properly versus when it does not (500 error) and they are identical:
Date: Sat, 08 Sep 2007 13:59:19 GMT
Server: Apache
Last-Modified: Sat, 08 Sep 2007 13:31:29 GMT
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=”UTF-8″
200 OK
The fact that the 500 error occurs intermittently (normally every other time) is also very confusing. How is an identical Last-Modified header causing problems half the time? And why does disabling cache on my browser (Firefox) cause the problem to disappear?
If any experts out there want to weigh in on this, I’d love for you to do so. For now, I’m going to continue to use my “fix” by ignoring the Last-Modified when serving cached pages.
UPDATE (12/05/2007):
Reader Givver (see the comment here) has been kind enough to package everything here along with several improvements as well. Check it out here. Thanks Givver!
Posted in: