<div dir="ltr"><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">Hello,<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I am trying to understand how fastcgi_read_timout works in Nginx.<br>

<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">Here is what I wanna do:<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I list files (few MB each) on a distant place which I copy one by one (loop) on the local disk through PHP.<br>

</div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I do not know the amount of files I need to copy, thus I do not know the total amount of time I need for the script to finish its execution. What I know is that I can ensure is a processing time limit per file.<br>

</div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I would like my script not to be forcefully interrupted by either sides (PHP or Nginx) before completion.<br><br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">

What I did so far:<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">- PHP has a 'max_execution_time' of 30s (default?). In the loop copying files, I use the set_time_limit() procedure to reinitialize the limit before each file copy, hence each file processing has 30s to go: way enough!<br>

<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">- The problem seems to lie on the Nginx side, with the 'fastcgi_read_timeout' configuration entry.<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">

I can't ensure what maximum time I need, and I would like not to use way-off values such as 2 weeks or 1 year there. ;o)<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">What I understood from <a href="http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_read_timeout">the documentation</a> is that the timeout is reinitialized after a successful read: am I right?<br>

<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">The challenge is now to cut any buffering occurring on the PHP side and let Nginx manage it (since the buffering will occur after content is being read from the backend). Here is what I did:<br>

</div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">* PHP's zlib.output_compression is deactivated by default in PHP<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">

* I deactivated PHP's output_buffering (default is 4096 bytes)<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">* I am using the PHP flush() procedure at the end of each iteration of the copying loop, after a message is written to the output<br>

<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">Current state:<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">* The script seems to still be cut after the expiration of the 'fastcgi_read_timout' limit (confirmed by the error log entry 'upstream timed out (110: Connection timed out) while reading upstream')<br>

</div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">* The PHP loop is entered several times since multiple files have been copied<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">

* The output sent to the browser is cut before any output from the loop appears<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">It seems that there is still some unwanted buffering on the PHP side.<br>

</div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I also note that the PHP's flush() procedure doesn't seem to work since the output in the browser doesn't contain any message written after eahc file copy.<br>

<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">Am I misunderstanding something about Nginx here (especially about the 'fastcgi_read_timeout' directive)?<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">

Have you any intel/piece of advice on hte matter?<br><br>Thanks,<br clear="all"></div><div><font size="1"><span style="color:rgb(102,102,102)">---<br></span><b><span style="color:rgb(102,102,102)">B. R.</span></b><span style="color:rgb(102,102,102)"></span></font></div>


</div>