Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a PHP file in my /batch/ folder I run with an hourly CRON job. Unfortunately this process can often take a few minutes to complete so I have had to increase my fastcgi_read_timeout to 300 seconds for the entire server.

I was wondering if it would be possible to change the fastcgi_read_timeout directive for only files in my /batch/ folder and not the entire server. For example something like this...

location ~ \.php$ {
    fastcgi_pass   localhost:9000;  
    fastcgi_read_timeout 5;

    location /batch/ {
                fastcgi_read_timeout 300;

    include /usr/local/nginx/conf/fastcgi_params;

So basically all PHP files on the server would have a 5 second timeout except PHP files in my /batch/ folder. Is this possible?

share|improve this question
If you are running the script via cron, why is Nginx involved? If possible, call the PHP interpreter directly from cron and bypass nginx completely. (However, fastcgi_read_timeout is a valid directive for location context (as well as server and http contexts) and you can have multiple location blocks, each bearing that directive) – cyberx86 Apr 10 '12 at 2:18
I still like to manually run the script from a browser sometimes. – Hart Jones Apr 10 '12 at 2:23
In that case, have a second php script that forks a background process which runs your long running process directly in the php interpreter. Done right, the parent execution time is minimal and the child process execution time is unrelated to nginx. (What you are trying to do should work though, but by preventing nginx from being involved with the long running process itself, you avoid the need of hard-coding the time limit in nginx and have much more flexibility). – cyberx86 Apr 10 '12 at 2:29

Your Answer


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

Browse other questions tagged or ask your own question.