Online Dating Blog

Using WP-Cache on GoDaddy (500 Error)

Posted by:

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!

Find your Soul Mate at eHarmony. Sign up Today for a Free Profile! www.eHarmony.com


26

About the Author:

Brad initially struggled with online dating but over time became quite successful using it. He met his wife using online dating and has been giving advice and helping people improve their results since 2007. He has written a Free Online Dating Guide to help others find success with online dating. You can learn more about his personal experience using online dating and running this website here.

Discussion

  1. Thom Dyson  September 12, 2007

    Thanks. This has been a big help. I see that in the history of wp-cache there is a mention of problems with this response header in the past.

    I noticed that when I copy/paste your code, I get “smart quotes”, so I had to clean up the pasted text. Your code it right, it just didn’t come over cleanly for me.

    (reply)
  2. Brad  September 12, 2007

    Thanks for catching the smart quotes problem Thom. The quotes should now work properly when copied.

    (reply)
  3. Otto  September 13, 2007

    Excellent! I had that same problem ages ago and just concluded that GoDaddy sucks. Now I still know that GoDaddy sucks, but at least I know why!

    The fix appears to work for me. Thanks!

    (reply)
  4. Otto  September 13, 2007

    Also, I added these various “speedup” additions to wp-cache and they all appear to work okay with GoDaddy hosting:
    http://www.askapache.com/wordpress/wp-cache-speed-hack.html

    Basically these just force various content-length and cache-control headers onto the page output. Seems to cause no issues. Dunno how much speed it adds though.

    (reply)
  5. Scoot  October 3, 2007

    I am in the process of dealing with Go Daddy on this issue. Would it be OK with you if I send the support guys a copy of your post?

    (reply)
  6. Brad  October 4, 2007

    Scoot – that’s absolutely fine. I’d say share this with anyone you think might be able to fully explain/correct the issue.

    (reply)
  7. Derek  October 5, 2007

    I’ve modified my wp-cache-phase1.php as you posted above, and it seems to be working just fine. Thanks! Have you heard anything regarding what problems may be caused by ignoring the Last-Modified header?

    (reply)
  8. Brad  October 5, 2007

    Derek – I’ve not heard anything about problems this may cause. Also, I’ve had caching turned on for almost a month and have yet to see anything odd. If this does break something, it is minor enough that I’ve not noticed it yet! If I ever get a solid answer from someone on what this affects, I’ll be sure to update the article.

    (reply)
  9. Wahoo  October 6, 2007

    Thank you for sharing!

    (reply)
  10. Sandy Kemsley  October 10, 2007

    I just applied your mod to my WordPress install on GoDaddy, and so far, so good.

    (reply)
  11. Paul  October 24, 2007

    I have been playing with a similar problem on GoDaddy, but not with WP. Here is my code that can cause an error:

    $date = gmdate(‘D, d M Y H:i:s’);
    header( ‘Last-Modified: ‘.$date.’ GMT’ );
    //header( ‘Last-Modified: ‘.$date );
    echo $date;

    And here is my code that works fine:

    $date = gmdate(‘D, d M Y H:i:s’);
    //header( ‘Last-Modified: ‘.$date.’ GMT’ );
    header( ‘Last-Modified: ‘.$date );
    echo $date;

    Spot the difference!
    (Hint: Look at \\ comments)

    (reply)
  12. calvin  November 6, 2007

    I found this:

    http://www.askapache.com/htaccess/apache-speed-last-modified.html

    Is it good or bad?

    (reply)
  13. Gene Steinberg  November 21, 2007

    I think, instead of trying to induce GoDaddy to make your sites and/or plugins work, you do the logical thing, which is to leave as fast as you can.

    When I had my sites on GoDaddy, I encountered slow performance and dreadful support. Listen, my office is up the street from them and I still wouldn’t stay.

    When they tried to hijack one of my domains, that was the straw that broke the camel’s back.

    There are lots and lots of hosts who deserve your business. GoDaddy isn’t one of them.

    Peace,
    Gene

    (reply)
  14. Brad  November 21, 2007

    Hey Gene – I appreciate your thoughts. For me, my financial situation didn’t allow for the option of immediately moving to another hosting provider. This limited my options to either trying to fix the code or just not using the plug-in.

    Now, my site doesn’t receive traffic to merit using any caching, really, so I should have abandoned the idea right then. But I enjoy trying to figure things out like that so I went down the path of trying to fix it.

    Personally, I’ve not had any issues since fixing this problem and I’ve been very happy. I have heard many people make similiar arguments as you do against GoDaddy but for the time being, I am content.

    (reply)
  15. Dj  November 27, 2007

    Good work dude ..
    Thanks

    (reply)
  16. Tom  December 1, 2007

    This worked great. Thanks.

    I haven’t really looked through the wp-cache code yet, but I’m assuming it could probably be simplified a lot. It usually only takes around 5 or 6 lines of code to cache a page.

    (reply)
  17. Givver  December 3, 2007

    For anyone who does not like to edit files or just wants an easy fix. I have made all the changes listed above for the GoDaddy fix and speed tweaks as well as enabling GZIP compression. You can find my blog with a .zip file that contains all the complete updated wp-cache at. http://www.givveronline.com/wordpress/godaddy-internal-server-error/ I have been using it now for about a week on GoDaddy with no problems.

    Great job Brad on figuring out how to fix this.

    (reply)
  18. Brad  December 5, 2007

    Thanks Givver! I’ll throw your link up in the article just in case people aren’t reading all the comments.

    (reply)
  19. Bill  February 19, 2008

    Thanks for everyone’s hard work. It really means a lot.

    (reply)
  20. Takuan Daikon  March 21, 2008

    Wow, thanks for posting the fix to this!!! I had, as you had said many do, disabled the plugin after I started receiving the errors.

    I don’t know why they started to happen, because for the first 24 hours things were just fine, but then I started gettingn 500 errors.

    Your suggested fix worked, and your explanation is very much appreciated. Thank you!

    (reply)
  21. Cialisoa  July 16, 2008

    Nice Article

    (reply)
  22. Ehud  August 24, 2008

    Thanks for the info. I too am trying to fix an issue with Smarty templates with caching enabled (which apparently WP uses too).

    Was there ever a response from GoDaddy regarding the cause of the problem?

    (reply)
  23. Ehud  August 24, 2008

    Paul: I tried your PHP sample on GoDaddy and both headers work fine.

    Gene Steinberg: Yes, GoDaddy is definitely slow; the hosted site’s response times, their super-slow and extra-convoluted management areas (plus the path you have to take to get to them), their arbitrary limitations on emails, and apparently also strange problems like this.

    But it’s difficult to know who’s a good host without trying. Any suggestions?

    (reply)
  24. Chris Hammett  January 29, 2009

    I don’t have the plug in that speak of, but I am hosting my wordpress blog on godaddy. Are there any other solutions that you can suggest? Right now I can’t delete a post without a 500 Internal Server Error. I was surprised to hear that someone spent 30 minutes with them on the problem (although that didn’t fix it.) All I here from them is “we don’t support that”. Of course they did advise me to search forums for the answer. So, here I am. Help?

    (reply)
  25. Brad  January 30, 2009

    Chris: Are you getting the 500 error every single time you try to delete a post or intermittently? I know my issue was not happening every time but almost every other time. Honestly, I

    (reply)
  26. Milan  April 22, 2009

    Is this still necessary? I am using the latest version of Super Cache 0.9.4.2 on my GoDaddy site and it seems to be working properly.

    (reply)

Add a Comment