My Ubuntu server is configured with Apache 2.2.8 and PHP 5.2.4-2ubuntu5.18 in FastCGI mode. Everything works well, except I am seeing 500 errors that only seem to come from bots accessing the server.. for example (access.log):
x.125.71.104 - - [16/Nov/2011:10:27:39 +1100] "GET / HTTP/1.1" 500 41377 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
x.40.103.239 - - [16/Nov/2011:11:05:56 +1100] "GET / HTTP/1.0" 500 14717 "-" "Mozilla/5.0 (compatible; mon.itor.us - free monitoring service; http://mon.itor.us)"
x.249.67.114 - - [14/Nov/2011:20:57:17 +1100] "GET / HTTP/1.1" 500 101 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
x.55.39.85 - - [14/Nov/2011:19:31:06 +1100] "GET / HTTP/1.1" 500 7032 "-" "msnbot/2.0b (+http://search.msn.com/msnbot.htm)._"
It is my understanding that a 500 error will be thrown when the PHP process fails to respond to Apache, which could be caused by a fatal PHP error or if PHP runs out of processes.. so my assumption is that either the bots are hitting the server too hard, killing the PHP processes, or something in the request header from bots is causing a fatal error in my PHP script? If anyone can offer advice on this it would be greatly appreciated!
Ryan
Do you want bots indexing your site? If not I wouldn't worry about it. If you do, check PHP error logs (
/var/log/php
is usually a good default place to look) and see what's causing PHP to trip up for bots.They may be providing no GET params or POST data to a script which requires it to function properly. In this case I would handle the request better, possibly returning a
404
if the script is wrapping a DB query (since nothing can be found unless you provide the appropriate params). If they are doing something even stranger, maybe returning a400 Bad Request
is in order.Check out this site to see if it has the information you need. http://redmine.lighttpd.net/projects/1/wiki/Docs:PerformanceFastCGI
All the way down where it says "Why is my php application returning 500 from time to time?"
For those with the 500 errors, the first line in this code needs to point to a unix socket, not a TCP/IP address / port – this is on Ubuntu 12.10.x – if you look inside
/etc/php5/fpm/pool.d/www.conf
you will find FPM is set up to listen to a unix socket.