Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have PHP5-CGI installed, Apache, and MYSQL installed. Prior to adding these settings, PHP5-CGI would endlessly have >15 processes, each eating up 5 mb of ram. So I added these settings to /etc/apache2/conf.d/php5-fcgid.conf and the PHP5-cgi processes were limited. However, now, everytime I open let's say 20 threads/pages in 4 or 5 minutes, the server stops running properly, things freeze and pages stop loading, until 2 or 3 minutes pass by, then it's lightening bolt fast again.

  AddHandler fcgid-script .fcgi .php                                        
  # Where to look for the php.ini file?                                     
  DefaultInitEnv PHPRC  "/etc/php5/cgi"                                     
  # Where is the PHP executable                                             
  FCGIWrapper /usr/bin/php-cgi .php                                         
  # Maximum requests a process handles before it is terminated              
  MaxRequestsPerProcess 1500                                                
  # Maximum number of PHP processes.                                        
  MaxProcessCount       15                                                  
  # Number of seconds of idle time before a process is terminated           
  IPCCommTimeout        240                                                 
  IdleTimeout           240                                                 


# Large site                                                                

  ServerLimit          2048                                                 
  ThreadLimit           100                                                 
  StartServers           10                                                 
  MinSpareThreads        30                                                 
  MaxSpareThreads       100                                                 
  ThreadsPerChild        64                                                 
  MaxClients           2048                                                 
  MaxRequestsPerChild  5000  

I am running a website (smf forum) that averages around 450 users per 20 minutes, so it gets a little hectic. So, what's going on?

share|improve this question
1  
(1) FYI, dump is a unix backup program. There are far more precise ways to describe your problem that avoid confusion with that utility. (2) We need more information to troubleshoot. Log files, activity statistics, etc. See meta.serverfault.com/questions/3608/… and try to give us a little more detail so we can help you... –  voretaq7 Nov 29 '12 at 0:04
1  
I meant to say it that way, sorry thought it would be funny. By the way, it just had a bowel movement again. –  Pete Nov 29 '12 at 0:04
    
woretaq7, should I look at apache logs? Or MYSQL logs, MYSQL logs have been disabled, don't know how to enable them actually. –  Pete Nov 29 '12 at 0:06
    
Actually, I was thinking core dump. "Server locks up" sounds like a better description but needs more detail (is it only the webserver or does ssh stop? Only on PHP requests or are static images stalled too?) –  DerfK Nov 29 '12 at 0:06
    
@Pete "yes" (you should look at all relevant logs. see the meta question). We aren't psychic - we can't tell you what's wrong without data. This could very well be a DB bottleneck, so slow query logs from MySQL would be pretty important to have... –  voretaq7 Nov 29 '12 at 0:07

1 Answer 1

The first thing I see right off the bat is that your FCGIWrapper looks like the actual php-cgi executable rather than a wrapper script that configures the environment variables PHP expects with values that will work with fcgid. By default PHP quits after 500 requests, but you have fcgid expecting them to last for 1500. You can find examples and an explanation in Apache's documentation but basically you need to set the PHP_FCGI_MAX_REQUESTS environment variable for php-cgi to be greater than the MaxRequestsPerProcess setting fcgid is using.

You can probably skip the wrapper script and just use DefaultInitEnv PHP_FCGI_MAX_REQUESTS 1501 in your Apache config

Also, your configuration is old, all of the directive names have changed but the old ones are usable for now.

share|improve this answer
    
Thanks for answering, but I'm really new to all this. What should I change exactly in the code that I displayed? change: DefaultInitEnv PHPRC "/etc/php5/cgi" to DefaultInitEnv PHP_FCGI_MAX_REQUESTS 1501 Is that what you mean? –  Pete Nov 29 '12 at 0:20
    
You'll need to have two DefaultInitEnv lines. –  DerfK Nov 29 '12 at 0:23
    
Okay, I will add: DefaultInitEnv PHP_FCGI_MAX_REQUESTS 1501 right below it; should I change 1500 to 500 as well? –  Pete Nov 29 '12 at 0:24
    
@Pete no, the purpose of this is to keep PHP from killing itself without fcgid knowing about it. With PHP_FCGI_MAX_REQUESTS set to 1501, PHP won't kill itself until the 1501st request, so it will still be there for fcgid to kill after the 1500th request. –  DerfK Nov 29 '12 at 0:30
    
Oh, what I meant to say was, change MaxRequestsPerProcess from 1500 to 500, and add DefaultInitEnv PHP_FCGI_MAX_REQUESTS 1501 underneath DefaultInitEnv PHPRC "/etc/php5/cgi". –  Pete Nov 29 '12 at 0:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.