Page 2 of 2

Re: php-cgi eat up the memory

Posted: Fri Mar 21, 2014 2:28 am
by enterpr1se
I think I solved the problem.
I dig many articles and there are some parameter need to add if someone face same problem

Acrossing to the document from apache, http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
PHP_FCGI_CHILDREN should set to 0 due to any child processes created by PHP will not be used effectively. (Additionally, the PHP child processes may not be terminated properly.)
That's why so many php-cgi process was created but not close properly.
The file location is in /home/YOUR_USER/web/YOUR_WEB/cgi-bin/fcgi-starter

Second, edit /etc/httpd/conf.d/fcgid.conf
these parameter should be added after "LoadModule fcgid_module modules/mod_fcgid.so"

Code: Select all

FcgidMinProcessesPerClass 0 #no process will be created if the user not active
FcgidMaxProcessesPerClass 16 
FcgidMaxProcesses 150
FcgidIdleTimeout 60 #if the process idle 60s will be killed
FcgidProcessLifeTime 120
FcgidIdleScanInterval 30
 

# Change the rate at which new FastCGI processes are spawned under load. Higher=faster
FcgidSpawnScoreUpLimit 10

# Higher number = spawning more FastCGI processes decreases the spawn rate (controls runaway
FcgidSpawnScore 1

# Higher number = terminating FastCGI processes decreases the spawn rate (controls runaway)
FcgidTerminationScore 2

# Increase the FastCGI max request length for large file uploads (needed for some sites)
FcgidMaxRequestLen 1073741824

FcgidMaxRequestsPerProcess 100000
FcgidIOTimeout 1800
REMEMBER BACKUP THE FILE BEFORE YOU EDIT

Re: php-cgi eat up the memory

Posted: Mon Apr 14, 2014 5:35 pm
by mephivio
Ok cool
i will test it soon !

But, Imperio, could you confirm the solution proposed by enterpr1se is correct ?

Thx !

Re: php-cgi eat up the memory

Posted: Wed Apr 16, 2014 8:13 pm
by imperio
Hi,
Yes, you can try to use instruction of enterpr1se
if you have any problems let me know

Re: php-cgi eat up the memory

Posted: Sat Apr 19, 2014 10:54 pm
by demlasjr
I had the same issue with fastcgid.

As enterpr1se said, the solution is to edit /etc/httpd/conf.d/fcgid.conf (CentOS) or /etc/apache2/mods-available/fcgid.conf (Ubuntu) and will work. I have something like this:

Code: Select all

<IfModule mod_fcgid.c>
  AddHandler    fcgid-script .fcgi
  FcgidConnectTimeout 20
  FcgidMinProcessesPerClass 0
  FcgidMaxProcessesPerClass 10
  FcgidMaxProcesses 50
  FcgidIdleTimeout 60
  FcgidProcessLifeTime 120
  FcgidIdleScanInterval 30


  # Change the rate at which new FastCGI processes are spawned under load. Higher=faster
  FcgidSpawnScoreUpLimit 10

  # Higher number = spawning more FastCGI processes decreases the spawn rate (controls runaway
  FcgidSpawnScore 2

  # Higher number = terminating FastCGI processes decreases the spawn rate (controls runaway)
  FcgidTerminationScore 2

  # Increase the FastCGI max request length for large file uploads (needed for some sites)
  FcgidMaxRequestLen 1073741824

  FcgidMaxRequestsPerProcess 100000
  FcgidIOTimeout 1800
</IfModule>

Then restart the apache.

What will this do? Will limit the processses per class to 10 and max 50 processes in total. Every process will automatically kill after 60 seconds (before never killed itself and used most of the ram in idle). Doing this, you will reduce the ram usage with 70%

Image

Re: php-cgi eat up the memory

Posted: Tue Aug 26, 2014 11:33 am
by Trentor
Hi,

Thank you enterpr1se and demlasjr, my problem with RAM and php-cgi seems solved.

Thanks!!

Re: php-cgi eat up the memory

Posted: Thu Jan 01, 2015 4:24 pm
by iamkingsleyf
enterpr1se wrote:I think I solved the problem.
I dig many articles and there are some parameter need to add if someone face same problem

Acrossing to the document from apache, http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
PHP_FCGI_CHILDREN should set to 0 due to any child processes created by PHP will not be used effectively. (Additionally, the PHP child processes may not be terminated properly.)
That's why so many php-cgi process was created but not close properly.
The file location is in /home/YOUR_USER/web/YOUR_WEB/cgi-bin/fcgi-starter

Second, edit /etc/httpd/conf.d/fcgid.conf
these parameter should be added after "LoadModule fcgid_module modules/mod_fcgid.so"

Code: Select all

FcgidMinProcessesPerClass 0 #no process will be created if the user not active
FcgidMaxProcessesPerClass 16 
FcgidMaxProcesses 150
FcgidIdleTimeout 60 #if the process idle 60s will be killed
FcgidProcessLifeTime 120
FcgidIdleScanInterval 30
 

# Change the rate at which new FastCGI processes are spawned under load. Higher=faster
FcgidSpawnScoreUpLimit 10

# Higher number = spawning more FastCGI processes decreases the spawn rate (controls runaway
FcgidSpawnScore 1

# Higher number = terminating FastCGI processes decreases the spawn rate (controls runaway)
FcgidTerminationScore 2

# Increase the FastCGI max request length for large file uploads (needed for some sites)
FcgidMaxRequestLen 1073741824

FcgidMaxRequestsPerProcess 100000
FcgidIOTimeout 1800
REMEMBER BACKUP THE FILE BEFORE YOU EDIT
Thanks for this solution

Re: php-cgi eat up the memory

Posted: Wed Apr 01, 2015 3:55 am
by DjarumSuper
Ah this is it

Thank you very much