Welcome! Log In Create A New Profile


Browser closes connection on time consuming php scripts

Posted by dantes 
Browser closes connection on time consuming php scripts
August 18, 2012 07:55AM

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?

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 115
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready