Multiple PHP_CGI process eating up my memory

I am hosting around 10 Joomla/Wordpress sites on my Dedicated Linode 4G server with Ubuntu18.04/Apache/Mysql.

All of these sites are for testing purpose, so there aren't many visitors, and I don't have any fancy stuff going on with these sites. However, more and more often, mysql service gets killed because of OOM issue and my sites are becoming very slow from time to time sometimes also return PHP fatal error saying failure to allocate memory.

So my questions are:
1) Excluding impact from visitors, generally around how many php sites can a 4G system host without having OOM issues? i.e. should I consider upgrade my system? I am afraid if the OOM is caused by something else, even if I upgrade to 8G I might still be getting this issue.

2) If the OOM issue is not natural, then I need to figure out whether it is caused by some misconfiguration of the server of by some bad PHP programming, or even being attacked. Upon checking "top", I found this:screenshot A friend of mine says there shouldn't be so many php-cgi processes when there are very few visitors and he says this might be the cause but he didn't have time to investigate further. Can anyone share more information regarding this?

1 Reply

IMHO, you should't be using php-cgi at all! php has delivered its own FastCGI process manager for quite some time now. It's called php-fpm.

php-fpm is multi-threaded and communicates with apache2 using sockets (my setup uses Unix-domain sockets…for increased performance and security). See: https://dev.to/joetancy/php-fpm-with-apache2-2mk0

Once you do that, you can start using one of the multithreaded apache2 MPMs -- mpm-worker or mpm-event -- which will decrease the number of apache2 processes you have as well. The mpm-prefork setup shown in your screenshot is dog slow…

To be fair to your screenshot though, whoever took it is trying to service multiple users with several different versions of php. This can easily be done with php-fpm and still get all it's/apache2's performance/footprint benefits.

php-cgi is sooooo 1990s… ;-)

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct