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 a vps on CentOS. It's configured using PLESK panel. PHP is run by apache and fcgid. I have problem with PHP ending premature when script running for like 10-15 minutes and sending 504 Gateway Time-out page. First I thought that my PHP max_execution_time is set to wrong value. So I set it to 900 seconds. But the problem still exists. So I searched google for an answer and found out that I should change mod-fcgid timeout values. I changed it to:

# This is the Apache server configuration file for providing FastCGI support
# via mod_fcgid
#
# Documentation is available at http://fastcgi.coremail.cn/doc.htm

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule mod_fcgid.c>

<IfModule !mod_fastcgi.c>
    AddHandler fcgid-script fcg fcgi fpl
</IfModule>

FcgidIPCDir /var/run/mod_fcgid/sock
FcgidProcessTableFile /var/run/mod_fcgid/fcgid_shm

FcgidIdleTimeout 960
FcgidProcessLifeTime 3600
FcgidMaxProcesses 20
FcgidMaxProcessesPerClass 8
FcgidMinProcessesPerClass 0
FcgidConnectTimeout 30
FcgidIOTimeout 960
FcgidInitialEnv RAILS_ENV production
FcgidIdleScanInterval 10

</IfModule>

It didn't work. It made my script run for a little more time and without 504 Gateway Time-out but still terminating to early.

This is my test script in PHP.

$start = date('Y-m-d H:i:s');
sleep(840);
$end = date('Y-m-d H:i:s');
var_dump(array($start, $end));

At the end I get:

array(2) {
  [0]=>
  string(19) "2013-10-17 18:57:46"
  [1]=>
  string(19) "2013-10-17 19:02:48"
}

Only 4 minutes between start and end. Any idea why sleep didn't work as expected?

share|improve this question

1 Answer 1

OK. I think I found solution to my problem. After askong google for apache fcgid five minutes i found some PDF (http://people.apache.org/~trawick/AC2010-FastCGI.pdf) that states:

By default, if a request does not complete within five minutes
the application will be terminated.
No way to disable. Fixme.

# my report generates output over a long period of
# time; don’t kill it
FcgidBusyTimeout 3600

# kill anything that doesn’t respond within 30
# seconds
FcgidBusyTimeout 30

So I've added FcgidBusyTimeout 990 to my mod_fcgid configuration and now sleep() works as expected.

share|improve this answer

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.