Sunday, 2 December 2012

Going to Church

Today I checked the stats for my websites, and noticed a load of 499 Unknown Errors on one of my sites. I couldn't find much info online on 499 errors, so I downloaded the server logs for the site. Looking at the log, I had regular errors such as: - - [25/Dec/2011:06:41:52 +0000] "POST /wp-cron.php?doing_wp_cron HTTP/1.0" 499 0 "-" "WordPress/3.2.1;"

(Yes, that error message is from Christmas Day 2011 - looks like this problem has been around a long time but I'd somehow not noticed it). Doing some googling, I found posts from people about wp-cron using too much memory and killing their sites. I didn't think this was the issue here though.

Then I found this post: WordPress: ошибка 499 wp-cron.php в связке Apache + Nginx. With the wonders of Google Translate, it seems the problem is that when someone requests a page, wordpress will fire the wp-cron function. This makes a request to /wp-cron.php?doing_wp_cron, and immediately severs the connection (so the user doesn't have to wait for the cron job to finish before the page they requested loads). But apparently Nginx sees the connection was severed, and so returns a 499 error. (And the cron job is not done).

In that article they suggest making the timeout 5 seconds, and also to make php sleep for 5 seconds. I think this would mean that any time a user visits a page and a wp-cron job is fired, that the user would have to wait 5 seconds though. Instead I have changed the timeout to 0.1s (from 0.01s) and added a 0.1 sleep. I will have to wait a week or so to see if this works. If not, I will use the other option of disabling wp-cron, and using a real cron to request the wp-cron page every so often.

I also unlocked and rooted my Nexus 7 while waiting for the server logs to download. There seem to be quite a lot of errors in my server logs, so I'm going to have to look into some of them a bit more tomorrow.

No comments: