# 504 Timeout when running PHP script

**URL:** <https://www.ruby-forum.com/t/504-timeout-when-running-php-script/185223>\
**Category:** NGINX\
**Created:** [March 16, 2010, 11:09am UTC](https://www.ruby-forum.com/t/504-timeout-when-running-php-script/185223 "2010-03-16T11:09:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [March 16, 2010, 11:09am UTC](https://www.ruby-forum.com/t/504-timeout-when-running-php-script/185223/1 "2010-03-16T11:09:06Z")

</div>

I have a PHP script that processes a folder of images, it takes quite a  
while to do this, but should produce output as it goes along. But when  
running this script I get a 504 Timeout, probably after 60s. The script  
also appears to stop running, so I end up with some database records  
written, and others not. (Does nginx send a signal to the fastcgi  
process to tell it to stop what it’s doing and get on with the next  
request?)

I checked the Nginx logs for the site, and weirdly there wasn’t anything  
in there about the timeout (I’m using the default error log level).

I’m running PHP as fastcgi, the relevant section of the Nginx config is:

location /admin/ {  
auth\_basic “Restricted”;  
auth\_basic\_user\_file  
/home/djeyewater/SSI/davidkennardphotography/.htpasswd;

```
#rewrite any .xhtml page to page.php
rewrite ^/(.+)\.xhtml$ /$1.php;

```

}

location /admin/batch-upload.php {  
auth\_basic “Restricted”;  
auth\_basic\_user\_file  
/home/djeyewater/SSI/davidkennardphotography/.htpasswd;  
add\_header Cache-Control “private, must-revalidate”;  
fastcgi\_read\_timeout 1200;  
fastcgi\_pass  
unix:/home/djeyewater/webapps/php/php.sock;  
}

location ~ ^/admin/.\*.php {  
auth\_basic “Restricted”;  
auth\_basic\_user\_file  
/home/djeyewater/SSI/davidkennardphotography/.htpasswd;  
add\_header Cache-Control “private, must-revalidate”;  
fastcgi\_read\_timeout 120;  
fastcgi\_pass  
unix:/home/djeyewater/webapps/php/php.sock;  
}

And I’m accessing the page as /batch-upload.xhtml

Thanks

Dave

Posted at Nginx Forum:

> **[504 Timeout when running PHP script](https://forum.nginx.org/read.php?2,64302,64302#msg-64302)**
>
> I have a PHP script that processes a folder of images, it takes quite a while to do this, but should produce output as it goes along. But when running this script I get a 504 Timeout, probably after 60s. The script also appears to stop running, so I...

---

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [March 16, 2010, 12:52pm UTC](https://www.ruby-forum.com/t/504-timeout-when-running-php-script/185223/2 "2010-03-16T12:52:08Z")

</div>

Hi,

> I have a PHP script that processes a folder of images,  
> it takes quite a while to do this, but should produce  
> output as it goes along. But when running this script I  
> get a 504 Timeout, probably after 60s. The script also  
> appears to stop running, so I end up with some database  
> records written, and others not. (Does nginx send a  
> signal to the fastcgi process to tell it to stop what  
> it’s doing and get on with the next request?)

I see you already set fastcgi\_read\_timeout to a high value on your  
server,  
so the problem may lie on the PHP side.

Check your max\_execution\_time (have a look at the memory limits aswell)  
in  
php.ini to make sure PHP itself does not trigger a timeout. You should  
also  
make sure that your script does not use output buffering (and also  
disable  
output buffering in php.ini), and it flushes its output immediately  
(check  
out the implicit\_flush directive on php.ini).

greetings,  
alex

---

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [March 17, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/504-timeout-when-running-php-script/185223/3 "2010-03-17T12:58:24Z")

</div>

## Alexander Vogt Wrote:

> greetings,  
> alex

Thanks for the advice, I did what you suggested and the page now works  
okay.

Regards

Dave

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,64302,64746#msg-64746](http://forum.nginx.org/read.php?2,64302,64746#msg-64746)
