Hey,
I have several PHP scripts that are time consuming, mainly because they approach to REST apis... The amount of time that each script consumes relies on the user input...
On apache everything works fine, however on Nginx the connection just got closed. When the processing time is low, everything is fine. The problem comes on the long requests...
There is no error in none of the logs. I suspect that the browser closes the connection.
I sniffed the headers, and it appears that Nginx doesn't send any response, until the processing is done. Not a single header.
I tried sending headers from the script, but it seems that nginx caches them all.
Afterwards, I disabled PHP output buffering and enabled implicit flush. I disabled gzip compression and zlib. I minimize FAST_CGI_BUFFERS to the minimum allowed, which is: fastcgi_buffers 2 1k; fastcgi_buffer_size 1k; fastcgi_busy_buffers_size 1k; fastcgi_max_temp_file_size 0;
Still, it refuse to send headers...
So just to prove my case, in one of the loops inside the code, I did a var_export to one of the objects...
BOOM!!! - it works...
I tried to find a better solution, so I played with keepalive_timeout and send_timeout. I tried different variations. Nothing works, except of:
keepalive_timeout: 1200s;
send_timeout: 1200s;
HOWEVER, it takes 11 minutes to display result on screen! The real time that the script runs is 180-200 seconds...
What should I do? How can I solve this?
Thanks.