2

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

quanta
  • 50,327
  • 19
  • 152
  • 213
Ryan D
  • 21
  • 2

3 Answers3

1

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 a 400 Bad Request is in order.

  • Unfortunately there is no /var/log/php file.. I'll switch the config in php.ini to log_errors = On, error_log = /var/log/php and see what I can find. Thanks! – Ryan D Nov 16 '11 at 00:54
  • No worries :) It may also be at `/var/log/apache2/error.log`, actually. –  Nov 16 '11 at 00:55
  • Aha, I've found a direct correlation between the 500 errors in access.log and the following error in error.log: `[Wed Nov 16 14:05:59 2011] [warn] (103)Software caused connection abort: mod_fcgid: ap_pass_brigade failed in handle_request function` Problem is, I have no idea how or why this error is being casued? – Ryan D Nov 16 '11 at 03:10
  • Try setting some memory-related options for FastCGI: `PHP_FCGI_MAX_REQUESTS=5000` `PHP_FCGI_CHILDREN=8` or similar. –  Nov 16 '11 at 03:43
  • Thanks for that. I already have `PHP_FCGI_MAX_REQUESTS=5000` configured, however I have not set a value for `PHP_FCGI_CHILDREN=8`. [Further reading](http://wherethebitsroam.com/blogs/jeffw/apache-php-fastcgi-and-phpfcgichildren) suggests not setting PHP_FCGI_CHILDREN. But I have now just realised I think I may be getting confused between [FastCGI and FCGID](http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/) .. I'm loading `LoadModule fcgid_module /usr/lib/apache2/modules/mod_fcgid.so` should I be using fastcgi.so instead? – Ryan D Nov 16 '11 at 03:55
  • "mod_fcgid sports better control over spawning processes and error detection. mod_fastcgi has been around longer. Both support suEXEC, and both separate PHP from Apache, thus allowing Apache to run threaded workers if desired." Essentially the same, but try `fastcgi.so` if you want. –  Nov 16 '11 at 04:03
  • ok, i'll do some research into fastcgi then. fyi I did set `PHP_FCGI_CHILDREN=8` and noticed when running `# top` that there were up to 8 child processes created when receiving multiple requests, which works fine. but still getting the same `ap_pass_brigade failed` message in error.log - so unfortunately those settings you recommended didn't help.. – Ryan D Nov 16 '11 at 04:17
  • OK. I've reached the limit of my knowledge in that area then. Good luck! –  Nov 16 '11 at 04:41
0

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?"

1100110
  • 111
  • 3
0

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.

FastCgiExternalServer /var/www/php5.external -socket /var/run/php5-fpm.sock
AddHandler php5-fcgi .php
AddHandler php5-fcgi .wfr
Action php5-fcgi /usr/lib/cgi-bin/php5.external
Alias /usr/lib/cgi-bin/ /var/www/
slm
  • 7,355
  • 16
  • 54
  • 72