Follow this Blog!

Sep 13, 2013

f Comment

Why Does PHP Fast CGI Process Keep Dying?

Amazon If your server uses Nginx and PHP chances are you are running PHP Fast CGI to process your PHP code. This process is commonly labeled php5-cgi when you run the top command in Unix.

If you realize that your PHP FastCGI process keeps dying for no reason this article may help you solve this issue.

Why does my PHP FastCGI keep on dying?

One possible cause is that some other process is taking too much of the memory, and somehow that process kills the PHP FastCGI process or disables the PHP FastCGI process from respawning. In my situation it is the mysqld process. Below is a screenshot showing that the mysqld process, or MySQL daemon, is consuming more than 50% of the entire memory of the machine.

MySQL Daemon Consuming Lots Of Memory On Unix Machine

My php5-cgi process would shut down every couple of days, and I'd get a 502 Bad Gateway error when I try to access my website. To fix it I simply restart my php5-cgi process via the following Unix command.

sudo /etc/init.d/php-fastcgi restart

However this is only an interim fix. The permanent fix would not require that I reboot the PHP FastCGI process every now and then. Read on to see how I fixed the problem.


So the general solution is run top command and see what processes are consuming unreasonable amounts of memory, and take action to drive the memory consumption down.

In my situation I took some steps to make sure my MySQL daemon is no longer consuming too much memory. These steps are described in another post: Best Practices With MySQL Memory Tables to Minimize Memory Footprint of mysqld! The following screenshot shows that my MySQL daemon process is consuming normal amounts of memory.

MySQL Daemon Consuming Acceptable Amount Of Memory On Unix Machine

My problem is fixed! My php5-cgi process no longer shuts down once every couple of days.

Your situation may be different. If you need help just let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael