I have an apache2 server configured with MPM worker and php fast cgi. Lately the apache logs have been telling me that MaxClients is being reached frequently, even though it's already pretty high.

My server is now constantly going down, and I see a bunch of lines like this in the log:

[Sun Mar 06 04:25:40 2011] [error] [client 50.16.83.115] FastCGI: comm with (dynamic) server "/var/local/fcgi/php-cgi-wrapper.fcgi" aborted: (first read) idle timeout (20 sec)
[Sun Mar 06 04:25:40 2011] [error] [client 50.16.83.115] FastCGI: incomplete headers (0 bytes) received from server "/var/local/fcgi/php-cgi-wrapper.fcgi"

I can see that my php-cgi processes are pretty large (about 70mb on average).

Here's my apache configuration for MPM worker: KeepAlive ON KeepAliveTimeout 2

<IfModule mpm_worker_module>
    StartServers         5
    MinSpareThreads      10
    MaxSpareThreads      10
    ThreadLimit          64
    ThreadsPerChild      10
    MaxClients           20
    MaxRequestsPerChild  2000
</IfModule>

Heres my fastcgi apache configuration:

<IfModule mod_fastcgi.c>
  # One shared PHP-managed fastcgi for all sites
  Alias /fcgi /var/local/fcgi
  # IMPORTANT: without this we get more than one instance
  # of our wrapper, which itself spawns 20 PHP processes, so
  # that would be Bad (tm)
  FastCgiConfig -idle-timeout 20 -maxClassProcesses 1
  <Directory /var/local/fcgi>
    # Use the + so we don't clobber other options that
    # may be needed. You might want FollowSymLinks here
    Options +ExecCGI
  </Directory>
  AddType application/x-httpd-php5 .php
  AddHandler fastcgi-script .fcgi
  Action application/x-httpd-php5 /fcgi/php-cgi-wrapper.fcgi
</IfModule>

Here's my fastcgi wrapper:

#!/bin/sh
PHPRC="/etc/php5/apache2"
export PHPRC
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN

exec /usr/bin/php-cgi

Any help would be very very much appreciated!

link|improve this question

33% accept rate
feedback

migrated from stackoverflow.com Mar 7 '11 at 0:29

This question came from our site for professional and enthusiast programmers.

2 Answers

Your scripts are taking long than 20 seconds. Either increase the idle timeout value or investigate why they are taking all that time (eg. waiting for DB connections).

link|improve this answer
feedback

As far as I can tell, there was a problem with one of the extensions I had installed.

https://github.com/mreiferson/php-wkhtmltox/issues/11

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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