# How fastcgi temp works?

**URL:** <https://www.ruby-forum.com/t/how-fastcgi-temp-works/238840>\
**Category:** NGINX\
**Created:** [January 30, 2014, 6:44pm UTC](https://www.ruby-forum.com/t/how-fastcgi-temp-works/238840 "2014-01-30T18:44:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [January 30, 2014, 6:44pm UTC](https://www.ruby-forum.com/t/how-fastcgi-temp-works/238840/1 "2014-01-30T18:44:49Z")

</div>

Hello everybody,  
We are using nginx with php-fpm. Our application works as download  
aggregator. We download files from 3rd party servers and send it to  
client  
while it’s still being downloaded. It means that we can’t use  
X-Accel-Redirect, since file isn’t fully downloaded and X-Accel-Redirect  
sets Content-Length to actual file size. We set required headers in php  
and  
in cycle read chunks of file, prints it and flush it to output.  
Everything  
seems to work fine except large files (over 1GB) on slow download  
speeds.  
Downloading was interrupted at 1GB - it seemed like client has  
disconnected

- calling connection\_aborted in php returned true. I have found out that  
fastcgi\_max\_temp\_file\_size is 1GB by default - so I have increased it to  
2GB.  
Now how exactly does fastcgi temp file works? Does every request has its  
own  
temp file? Or is there one common temp file?  
Thanks for hints!

Posted at Nginx Forum:

> **[How fastcgi temp works?](https://forum.nginx.org/read.php?2,247019,247019#msg-247019)**
>
> Hello everybody, We are using nginx with php-fpm. Our application works as download aggregator. We download files from 3rd party servers and send it to client while it's still being downloaded. It means that we can't use X-Accel-Redirect, since file...

---

<div class="post-metadata">

**Author:** ![portoist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9c0ed/32.png) [@portoist](https://www.ruby-forum.com/u/portoist)\
**Post date:** [January 31, 2014, 2:44am UTC](https://www.ruby-forum.com/t/how-fastcgi-temp-works/238840/2 "2014-01-31T02:44:16Z")

</div>

Hello!

On Thu, Jan 30, 2014 at 12:44:25PM -0500, portoist wrote:

> fastcgi\_max\_temp\_file\_size is 1GB by default - so I have increased it to  
> 2GB.  
> Now how exactly does fastcgi temp file works? Does every request has its own  
> temp file? Or is there one common temp file?  
> Thanks for hints!

Some hints can be found here:

[http://nginx.org/r/fastcgi\_buffering](http://nginx.org/r/fastcgi_buffering)

Downloading is _not_ interrupted by nginx after reaching 1GB, but  
it will stop loading further data from a backend till already  
buffered data are sent. This may take a while if client  
connection is slow, leading to timeouts on backend’s side.

–  
Maxim D.  
[http://nginx.org/](http://nginx.org/)

---

<div class="post-metadata">

**Author:** ![portoist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9c0ed/32.png) [@portoist](https://www.ruby-forum.com/u/portoist)\
**Post date:** [January 31, 2014, 8:41am UTC](https://www.ruby-forum.com/t/how-fastcgi-temp-works/238840/3 "2014-01-31T08:41:07Z")

</div>

Thank you for your answer. I will try how it will work with  
X-Accel-Buffering: no in headers.  
It is strange. From backend it seems like client disconnects. Calling  
php  
connection\_aborted returns true. I am downloading file around 1.5GB with  
speed around 250KB/s. I have downloaded 600MB and I can see in my log  
from  
php, that I have disconnected. Also I know that file from 3rd party  
server  
is fully donwloaded - so there are data to send and that script uploaded  
1GB. But my download is still running. When I download 1GB downloading  
stops.

Posted at Nginx Forum:

> **[Re: How fastcgi temp works?](https://forum.nginx.org/read.php?2,247019,247046#msg-247046)**
>
> Hello everybody, We are using nginx with php-fpm. Our application works as download aggregator. We download files from 3rd party servers and send it to client while it's still being downloaded. It means that we can't use X-Accel-Redirect, since file...
