Our site is currently on a VPS and using nginx as the web server (which we found is LOADS better for memory usage than apache!). However, on occasion, it seems like our php-cgi processes just suddenly crash, and our users are left with a "502 Bad Gateway" error from nginx.
Our php fastcgi settings are the following:
PHP_FCGI_CHILDREN = 8 (should be plenty for our traffic)
PHP_FCGI_MAX_REQUESTS = 400 (used to be 1000, we tried lowering to see if it would help, and na-da.)
It is not memory issues, since we run monitoring to check our memory usage and we have enough buffer room to accommodate our processes.
Upon reading the http error logs, we see these sort of error messages:
*9 connect() to unix:/home/***/.php.sock failed (111: Connection refused) while connecting to upstream, client: *****, server: ****, request: "GET ****, upstream: "fastcgi://unix:/home/***/.php.sock:"
*28898 connect() to unix:/home/****/.php.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: **, server: **, request: "GET **", upstream: "fastcgi://unix:/home/***/.php.sock:"
We wrote a daemon that restarts the nginx web server when it detects the processes crash, or these error codes pop up, but sometimes restarting the web server fails to bring back the php5.cgi processes, and our users are left without any access to our site material for a while.
Why in the world is the php locking up and crashing like this, and why can't nginx automatically recover? Is there another way to serve php to our users that doesn't use php-cgi? (I heard some use php-fpm or something but I'm not too familar with using it). Going back to apache is not an option, since we have decently high traffic and nginx does a much better job of handling it than apache does.
We also use MySQL extensively, so could it be that the php is locking up waiting for the sql? If so, why does the php become unstable?
Thanks to anyone who can help... this problem has been driving us berserk for the last month or so.