# Nginx + PHP FASTCGI FAILS - how to debug?

**URL:** <https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489>\
**Category:** NGINX\
**Created:** [January 12, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489 "2010-01-12T19:06:14Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [January 12, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/1 "2010-01-12T19:06:14Z")

</div>

I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP  
FASTCGI via port 9000.

The server runs fine for a few minutes and after a few minutes (several  
thousands of hits in this case) FastCGI dies and Nginx returns 502  
Error.

Nginx log shows 2010/01/12 16:49:24 1093#0: \*9965 connect() failed  
(111: Connection refused) while connecting to upstream, client:  
79.180.27.241, server: localhost, request: “GET /data.php?data=7781  
HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host:  
“[site1.mysite.com](http://site1.mysite.com)”, referrer: “[http://www.othersite.com/subc.asp?t=10](http://www.othersite.com/subc.asp?t=10)”

How can I debug what is causing FastCGI to die ?

Posted at Nginx Forum:

> **[Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,40332#msg-40332)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [January 13, 2010, 1:46am UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/2 "2010-01-13T01:46:39Z")

</div>

On Tue, Jan 12, 2010 at 10:05 AM, Niro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

It appears to not be running or perhaps a firewall is blocking, but I  
am guessing the former.

– Merlin

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [February 12, 2010, 5:13am UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/3 "2010-02-12T05:13:53Z")

</div>

Same problem here.

This is with a clean install of Nginx 0.8.33 and Ubuntu Server 9.10.  
Will try with 0.7.65 soon.

Anyhow, Nginx with PHP FastCGI works fine for a while and then just  
dies. Time it works seems random to me.

If I restart Nginx and PHP FastCGI, web pages in php will load once  
again, but oddly it keeps trying to load any images / scripts / files,  
etc. using https now. I don’t have https. Agan this does not happen from  
the start.

Very strange behavior and does not happen until I start seeing 502  
Errors.

Have to reboot server for it to work again and it does every single time  
after a reboot.

Really confusing.

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,53772#msg-53772)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [February 12, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/4 "2010-02-12T14:21:40Z")

</div>

Hi,

> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000.
> 
> The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error.
> 
> Nginx log shows 2010/01/12 16:49:24 1093#0: \*9965 connect() failed (111: Connection refused) while connecting to upstream, client: 79.180.27.241, server: localhost, request: “GET /data.php?data=7781 HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “[site1.mysite.com](http://site1.mysite.com)”, referrer: “[http://www.othersite.com/subc.asp?t=10](http://www.othersite.com/subc.asp?t=10)”

I’ve experiencing something similar.  
After some time (some hours, but I’m getting not that much hits), PHP  
appears to be not responding anymore:  
Processes are running, but nginx times out:  
First with  
upstream timed out (110: Connection timed out) while reading  
response header from upstream  
then  
recv() failed (104: Connection reset by peer) while reading response  
header from upstream

This happened with php-cgi and a custom start script a few days ago  
(same symptoms, have not checked logs carefully), and today after I’ve  
switched to using php-fpm.

So, both php-cgi and php-fpm appear to not behave well with nginx.  
Those problems never appeared using lighttpd (in the same  
container/machine), but are happening now since I have only PHP  
running in the container/machine and nginx (acting as first proxy in  
line) is directly forwarding to it.

Maybe this did not happen with lighttpd before, because it (and the  
php-cgi process) was regularly restarted, which is not the case  
currently.

I’ve found [PHP :: Bug #39809 :: FastCGI Requests silently dropped](http://bugs.php.net/bug.php?id=39809)

I’m running PHP 5.3.1-0.dotdeb.1 and nginx 0.8.33-0~ppa2.

I guess this is rather a PHP than an nginx problem, since restarting  
php-fpm fixes it.

For now, I’ve tried bumping the number of child processes, hoping that  
this will prevent the PHP processes entering the ignoring state.

Here’s a munin graph from the PHP container  
([http://i.imgur.com/MHbNi.png](http://i.imgur.com/MHbNi.png)) - the failing started with the  
increasing number of established network connection: those are  
probably the connections from nginx queuing up, without being  
answered.

> How can I debug what is causing FastCGI to die ?

So in your case there aren’t any php-cgi processes anymore? Have you  
checked the php error log?

Cheers,  
Daniel

–  
[http://daniel.hahler.de/](http://daniel.hahler.de/)

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [February 12, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/5 "2010-02-12T15:08:29Z")

</div>

> So, both php-cgi and php-fpm appear to not behave well with nginx.

First of all - when running php in fastcgi mode you should understand  
that more or less the webserver is taken out of picture.

The php fastcgi service is a standalone process which listens on port or  
socket and doesnt actually care what webserver (as far as  
it can ‘talk fastcgi’) is used (of course there are some differences of  
how the webservers handle this or that situation/error  
(like lighttpd for example disables the backend for some time  
(configurable) if its not reachable and doesnt try to reconnect at  
that period).

But the basic principles which have worked for us (on a pretty big site  
with thousands of requests per sec) are such:

1. Use PHP-FPM! ( [http://php-fpm.org/](http://php-fpm.org/) ) while at the moment it requires  
you to patch and build your php from source (rather than  
installing some distro package) even the php developers themselves have  
admited that current php process manager is bassicaly shite.  
And for a good reason they have at last included the php-fpm in the 5.3  
tree (still experimental though).

Without php-fpm you bassically have no control over your fastcgi  
processes (except the ‘PHP\_FCGI\_MAX\_REQUESTS’) the master process  
can die / childs can get stuck in infinite loops or eat all of your ram  
in case of a leaking code / extension.

1. The typical problem we have encountered when php pages suddenly stop  
processing is either all the forked childs are doing some  
long (unintended) running scripts (as the inbuilt max\_max\_execution\_time  
doesnt always work (if at all) as expected) or just have  
been hanged so the master process has no free childs to assign the  
incomming request.

Thats why you:

- spawn more than just few childs. While the typical approach is to like  
go by cpu core count we have experienced that adding some  
multiplier like 3 - 4x works better as the php code tends usually to  
wait more from external resources (DBs etc) rather than  
processing code
- use the great features of php-fpm to monitor which scripts take too  
long to execute and kill those who are taking too long.

Like we use:

30s  
60s

Which means that requests taking more than 30 seconds to compute will be  
logged (backtraced) and those taking longer than minute  
killed by force.  
Has helped to to find all the infinite loops and other weird issues  
created by php coders or also opcode accelerators like eA ( look  
at this for example [http://www.eaccelerator.net/ticket/381](http://www.eaccelerator.net/ticket/381) )

- tune the process\_control\_timeout and emergency\_restart\_threshold  
settings so the php childs get respawned in case there are memory  
leaks/errors or the child gets stuck.

1. At last to debug whats the child is actually doing is easilly done  
with ‘strace’ .. Use ‘ps aux’ to see the process numbers and  
see what php child is taking cpu and then attach with ‘strace -p [pid]’  
and you can take a look what is the process doing (if  
anything).

rr

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [February 12, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/6 "2010-02-12T19:31:02Z")

</div>

Hello.

Few days ago, we got the same !! php-cgi process was running using all  
the CPU. I did need to kill them explicity. I could reproduce it,  
stressing the application with http\_load.

After upgrading eAccelerator to 0.9.6 Final (or disabling old version),  
all goes to normal behaviour.

Cent OS 5.4 64 bits  
php 5.3.1

Hope this helps.

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,53968#msg-53968)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [February 12, 2010, 3:14pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/7 "2010-02-12T15:14:56Z")

</div>

Few days ago I got something smillar, all php-cgi process was still  
running but I got error bad gateway, php-cgi ignored sigterm but after  
killing it with sigkill and start again seen to work. Odd.

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 4:44am UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/8 "2010-04-04T04:44:32Z")

</div>

Usu wrote:

> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

what are you seeing on the system side? whats your output of:  
dstat  
ulimit

also, how many connections are you allowing for your fast-cgi ?

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 4:24am UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/9 "2010-04-04T04:24:38Z")

</div>

Hi, I’m having the same problem for a few weeks now, after x hours/days  
php becomes unresponsive, I’ve already changed 2 different php-fastcgi  
spawning scripts and tried php-fpm as well, switched between many  
version of the php 5.2 and 5.3 branches but the problem still remains so  
I don’t think it’s a php issue even if that would be the most logical  
conclusion.

When php becomes unresponsive (502 bad gateway error) all the  
php-cgi/php-fpm processes are still running and I can see them in top/ps  
aux, when I restart php everything start to work again.

I don’t know if it’s releated, but while I was browsing this forum a few  
minutes ago I got the 502 error with the same behavior it has when it  
happens on my site, it lasted some minutes than someone took care of it.  
Also, take a look at this discussion:  
[http://groups.google.com/group/highload-php-en/browse\_thread/thread/a3809a50eba71a45](http://groups.google.com/group/highload-php-en/browse_thread/thread/a3809a50eba71a45)  
I think that this is a nginx bug, it would be nice if some developer  
could look into this, I could provide error logs and such if needed,  
just let me know, thanks!

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,70942#msg-70942)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 5:09am UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/10 "2010-04-04T05:09:41Z")

</div>

> Hi, I’m having the same problem for a few weeks  
> now, after x hours/days php becomes unresponsive,  
> I’ve already changed 2 different php-fastcgi  
> spawning scripts and tried php-fpm as well,  
> switched between many version of the php 5.2 and  
> 5.3 branches but the problem still remains so I  
> don’t think it’s a php issue even if that would be  
> the most logical conclusion.

You are probably have too many concurrent connections from nginx  
to your php-fastcgi application. Try to increase listen queue to 1024  
or something to handle your load spikes, benchmarking or whatever  
causing it.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,40332,70997#msg-70997](http://forum.nginx.org/read.php?2,40332,70997#msg-70997)

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 9:56am UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/11 "2010-04-04T09:56:28Z")

</div>

Hi, thanks for the replys.

ulimit output: unilimited  
To run dstat I will have to wait until php becomes unresponsive, it  
could be hours or days, I can’t reproduce it since it’s not releated to  
the load on the server, I tried stressing it with Apache Benchmark but  
even with all the cpus at 100% the site was still working fine (only  
slow), I use munin and every time it happens I don’t see any weird  
behavior apart form the mysql threads that have a spike.

PHP\_FCGI\_MAX\_REQUESTS = 500  
I’m using dynamic child with php-fpm (but I’ve already tried many  
setting here even without php-fpm)

Here’s the first part of the nginx configuration, let me know if you  
need the whole thing

user www-data www-data;  
worker\_processes 12;  
error\_log logs/error.log;  
pid /dev/shm/nginx.pid;  
worker\_rlimit\_nofile 10000;

events {  
worker\_connections 1024;  
use epoll;  
}

http {  
include mime.types;  
#include /etc/nginx/proxy.conf;  
include /usr/local/nginx/conf/fastcgi\_params;

```
default_type application/octet-stream;

 log_format main '$remote_addr - $remote_user [$time_local] 

```

“$request” ’  
'$status $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for 

```

some vhosts  
client\_max\_body\_size 12m;  
large\_client\_header\_buffers 8 32k;

```
# output compression saves bandwidth
gzip on;
gzip_proxied any;
gzip_http_version 1.1;
#gzip_min_length 1100;
gzip_comp_level 2;
#gzip_buffers 4 8k;
gzip_types text/plain text/css application/x-javascript 

```

text/xml application/xml application/xml+rss text/javascript  
application/atom+xml;  
#gzip\_vary on;  
#gzip\_disable “MSIE [1-6].”;

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,71034#msg-71034)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 9:00pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/12 "2010-04-04T21:00:37Z")

</div>

Only a bunch of apf (firewall) messages…

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,71181#msg-71181)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 8:38pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/13 "2010-04-04T20:38:58Z")

</div>

Hey, Also what is the output of your dmesg ?

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,71174#msg-71174)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 9:22pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/14 "2010-04-04T21:22:16Z")

</div>

No, nothing like that, not now, not when the php problem occurs, the  
system logs are clean.

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,71189#msg-71189)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [April 4, 2010, 9:19pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/15 "2010-04-04T21:19:56Z")

</div>

nothing saying that your out of sockets or mem or any messages about  
connection tracking modules being full?

Posted at Nginx Forum:

> **[Re: Nginx + PHP FASTCGI FAILS - how to debug ?](https://forum.nginx.org/read.php?2,40332,71187#msg-71187)**
>
> I have an Ubuntu 9.10 server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000. The server runs fine for a few minutes and after a few minutes (several thousands of hits in this case) FastCGI dies and Nginx returns 502 Error. Nginx log...

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [June 20, 2010, 11:29pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/16 "2010-06-20T23:29:14Z")

</div>

Usu wrote:

> Hi, I’m having the same problem for a few weeks now, after x hours/days  
> php becomes unresponsive, I’ve already changed 2 different php-fastcgi  
> spawning scripts and tried php-fpm as well, switched between many  
> version of the php 5.2 and 5.3 branches but the problem still remains so  
> I don’t think it’s a php issue even if that would be the most logical  
> conclusion.
> 
> When php becomes unresponsive (502 bad gateway error) all the  
> php-cgi/php-fpm processes are still running and I can see them in top/ps  
> aux, when I restart php everything start to work again.
> 
> I don’t know if it’s releated, but while I was browsing this forum a few  
> minutes ago I got the 502 error with the same behavior it has when it  
> happens on my site, it lasted some minutes than someone took care of it.  
> Also, take a look at this discussion:  
> [http://groups.google.com/group/highload-php-en/browse\_thread/thread/a3809a50eba71a45](http://groups.google.com/group/highload-php-en/browse_thread/thread/a3809a50eba71a45)  
> I think that this is a nginx bug, it would be nice if some developer  
> could look into this, I could provide error logs and such if needed,  
> just let me know, thanks!
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,40332,70942#msg-70942](http://forum.nginx.org/read.php?2,40332,70942#msg-70942)

I realize you may have moved on; some time has passed since you posted  
this problem. However, I had the same issue and I was able to fix it.  
The user nginx runs as in a default setup is “www-data”, or “nobody”.  
Nginx has insufficient permissions to communicate with  
fastcgi://127.0.0.1:9000 which usually runs as root. So if you use  
spawn-fcgi, you must run it with the -U flag, and specify the same user  
that nginx runs as. For example:

spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -f /usr/bin/php-cgi -U nobody

or if you use sockets

spawn-fcgi -s /var/run/fcgi.sock -C 5 -f /usr/bin/php-cgi -U nobody

My problem was identical to yours, php would work for a moment, then  
become unresponsive even though the processes were still running. I hope  
this helps, this problem was very frustrating.

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [August 11, 2011, 7:06pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/17 "2011-08-11T19:06:26Z")

</div>

I’m having this issue. PHP5-CGI just disappears after undetermined  
time(1 to 4 hrs).

I have the latest php, nginx and lighttpd installed on ubuntu

to get my web service back i need to re-spawn using this command

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f  
/usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

your help is appreciated

---

<div class="post-metadata">

**Author:** ![Niro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@Niro](https://www.ruby-forum.com/u/Niro)\
**Post date:** [August 12, 2011, 1:33pm UTC](https://www.ruby-forum.com/t/nginx-php-fastcgi-fails-how-to-debug/181489/18 "2011-08-12T13:33:44Z")

</div>

> /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f

I would suggest to use FPM php process manager (  
[PHP: FastCGI Process Manager (FPM) - Manual](http://www.php.net/manual/en/install.fpm.php) ) instead of 'spawn-fcgi ’  
. For a a  
while its in php core and preferred way use php in webservers with  
fastcgi interface.

rr
