I am constantly getting 504 Gateway Errors when my php script needs to run for longer than 60 seconds.
I am on Media Temple on a dedicated server. I have contacted Media Temple and they have been helpful but none of their suggestions seem to work for me. I was told to edit this file.
/etc/httpd/conf.d/fcgid.conf
which I have...see below
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 300
FcgidMaxRequestLen 1073741824
FcgidProcessLifeTime 10000
FcgidMaxProcesses 64
FcgidMaxProcessesPerClass 15
FcgidMinProcessesPerClass 0
FcgidConnectTimeout 600
FcgidIOTimeout 600
FcgidInitialEnv RAILS_ENV production
FcgidIdleScanInterval 600
</IfModule>
I have tried to max everything as much as I can. To test this I am just running the function below.
function test504(){
@set_time_limit(0);
sleep(60);
echo "true";
}
Sleep will work on any value below 60 seconds, but anything more results in a 504 Gateway Error
my phpinfo(); outputs
max_execution_time 600
max_input_time 180
I have seen a few posts on increasing the fastcgi_connect_timeout setting, but have no idea where to find this on Media Temple.
Can anyone help? Thanks.
** UPDATE **
After chatting with support I have been told I need to edit nginx.conf and was directed to this post http://blog.secaserver.com/2011/10/nginx-gateway-time-out/
I can't find any of the values in my server settings. client_header_timeout client_body_timeout send_timeout fastcgi_read_timeout
my nginx.conf file looks like this
#error_log /var/log/nginx/error.log info;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 120;
#tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server_tokens off;
include /etc/nginx/conf.d/*.conf;
}
** UPDATE **
I managed to get this sorted out and added a blog post on how I fixed it.
http://devsforrest.com/116/boost-settings-on-media-temple-for-maximum-settings
I too had the same issue and I solved it by editing nginx.conf file. In most cases, this can be fixed by adding / increasing the send_timeout directive in nginx.conf.
Find your nginx.conf file (usually located at /usr/local/nginx/nginx.conf
or sometimes /etc/nginx/sites-available/default
), open it using nano or any other text editor, and add the following lines between the http { } so it looks like:
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 120;
#tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server_tokens off;
send_timeout 10m;
include /etc/nginx/conf.d/*.conf;
}
In my case, I had to increase some other directives like:
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
fastcgi_read_timeout 10m;
too.
Once you've edited the file, just reload nginx with:
kill -HUP `ps -ef | grep nginx | grep master | awk {'print $2'}`
or
sudo service nginx restart
That should fix it.
(I found the directives here: http://blog.secaserver.com/2011/10/nginx-gateway-time-out/ )
PS: I saw the comment by the OP with a link to their blog but I thought adding the relevant information here might help.