My Apache is throwing Internal Server Error 500 errors and logs like this:

> [Sun Apr 07 23:35:24 2013] [error] [client] (2)No such
> file or directory: FastCGI: failed to connect to server
> "/home/magda_00aa/sportxxx.pl/sportxxx.pl.0fake": socket file
> descriptor (1063) is larger than FD_SETSIZE (1024), you probably need
> to rebuild Apache with a larger FD_SETSIZE, referer:
> http://www.surf4web.com/surfing.php?id=haoduodeng2012

I've upped FD limits inside:

cat /usr/include/bits/typesizes.h | grep FD
#define __FD_SETSIZE            65536


cat /usr/include/linux/posix_types.h | grep FD_SETSIZE
#undef __FD_SETSIZE
#define __FD_SETSIZE    65536

and also

/sbin/sysctl fs.file-max
fs.file-max = 512000

ulimit -n

but it didn't helped. My Apache is still crashing if more than 350 virtualhosts :/

I'm on CentOS 5.9 64-bit - kernel 3.0.65-1.el5.elrepo

  • Please note that the "fd_set" is a kernel structure, changing FD_SETSIZE would require recompiling the kernel itself. Otherwise, the kernel is still going to use a max of whatever the original is. Also the normal default is set to 1024 which uses 128 bytes of memory, 65536 requires 8k of memory per structure. – Rahly Dec 8 '13 at 8:13

This is because mod_fastcgi uses select() as a multiplexing option. Select is pretty bad for this stuff, the man page specifies for select;

An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger than FD_SETSIZE will result in undefined behavior. Moreover, POSIX requires fd to be a valid file descriptor.

FD_SETSIZE is normally 1024, so file descriptors over 1024 are not supported in general. You can fiddle with the FD_SETSIZE include sizes as you have done but making changes like this might impact other programs too which aim to be POSIX compliant. In my opinion, if the application writer is suggesting altering system source code to make this work then the application is fundamentally broken.

I suggest moving off of mod_fastcgi and using another implementation. Depending on how your staring your FastCGI daemons can depend on how you do this.

mod_fcgid is one option or newer apaches can use mod_proxy_fcgi instead.

  • I'm using php-fpm – Spacedust Apr 7 '13 at 23:35
  • FastCGI is merely a protocol, whatever you are using for the server side is not the issue, the client side is what is causing your issues. – Matthew Ife Apr 8 '13 at 18:18
  • 1
    How to recompile Apache properly ? I can't find any setting inside it's config files. – Spacedust Apr 8 '13 at 21:29
  • Recompiled apache and all working fine :D – Spacedust May 6 '13 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.