Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I recently moved from apache to a Nginx/fastcgi solution, I had it running on a Fedora system and had no problems, but, since i moved all to Gentoo , the Spawn-fCGI / fastcgi php daemon dies, and i can't find out any errors reports on /var/log/messages , so i don't know why this happens.

I've seen that fastcgi is somehow different from the fedora distro, on gentoo as it has different conf files and init.d startup scripts, Can someone help me make it more stable? The number of requests that i had isn't any different from the ones I had on fedora, so i use the default conf that comes with the distro..and in about some hours it simply dies...

Thank you very much

share|improve this question
    
Use php-fpm instead, it's loads more stable than vanilla php-cgi. –  Martin Fjordvald Apr 25 '11 at 16:24

3 Answers 3

Here is the content of my /etc/conf.d/php-cgi file (it's a modified copy of the original spawn-fcgi conf.d file) :

# The FCGI process can be made available through a filesystem socket or
# through a inet socket. One and only one of the two types must be choosen.
# Default is the inet socket.

# The filename specified by
# FCGI_SOCKET will be suffixed with a number for each child process, for
# example, fcgi.socket-1. 
# Leave empty to use an IP socket (default). See below. Enabling this, 
# disables the IP socket.
# 
FCGI_SOCKET=

# When using FCGI_PORT, connections will only be accepted from the following
# address. The default is 127.0.0.1. Use 0.0.0.0 to bind to all addresses.
#
FCGI_ADDRESS=127.0.0.1

# The port specified by FCGI_PORT is the port used
# by the first child process. If this is set to 1234 then subsequent child
# processes will use 1235, 1236, etc.
#
FCGI_PORT=2000

# The path to your FastCGI application. These sometimes carry the .fcgi
# extension but not always. For PHP, you should usually point this to
# /usr/bin/php-cgi.
#
FCGI_PROGRAM=/usr/bin/php-cgi
#FCGI_PROGRAM=/usr/bin/spawn-fcgi

# The number of child processes to spawn. The default is 1.
#
FCGI_CHILDREN=1

# If you want to run your application inside a chroot then specify the
# directory here. Leave this blank otherwise.
#
FCGI_CHROOT=

# If you want to run your application from a specific directiory specify
# it here. Leave this blank otherwise.
#
FCGI_CHDIR=

# The user and group to run your application as. If you do not specify these,
# the application will be run as root:root.
#
FCGI_USER=nginx
FCGI_GROUP=nginx

# Additional options you might want to pass to spawn-fcgi
#
#FCGI_EXTRA_OPTIONS=

# If your application requires additional environment variables, you may
# specify them here. See PHP example below.
#
#ALLOWED_ENV="PATH"

# PHP ONLY :: These two options are specific to PHP. The first is the number
# of child processes to spawn. The second is the number of requests to be
# served by a single PHP process before it is restarted.
#
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500
#
# For this to work you would set
ALLOWED_ENV="PATH PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS"

Then to create the init.d file, just make a symlink to the original spawn-fcgi init.d file with the name of your conf.d file (php-cgi in my case) :

% sudo ln -s /etc/init.d/spawn-fcgi /etc/init.d/php-cgi

Then you can start it with :

% /etc/init.d/php-cgi start

and add it to the default boot level

% rc-update add php-cgi default

The only degree of freedom you have is by tweaking these two values :

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

More children can handle more requests at the same time, but it consumes more memory.
Depending on your hardware configuration, adapt these two settings.

share|improve this answer

Got the exact same problem here... Fixed it by running spawn-fcgi in interactive mode (so that it doesn't fork) wrapped in an infinite while loop (so that it restarts).

share|improve this answer

I got the same problems...

I encountered two solutions :

  • cron the fastcgi restart : "0 * * * * /etc/init.d/fastcgi restart". It is ugly but it works
  • the problem appears to come from the php-cgi process that become unstable after long time. This can be fixed forcing php-cgi to renew the processes after a max number of requests, by a env variable : "export PHP_FCGI_MAX_REQUESTS=500"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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