Question

I've got apache as a back-end server, which runs php scripts and nginx as a reverse-proxy server which deals with static content. A php-script, which gives me ID of some process and then performs this process (pretty long). I need to pass to browser only the ID of that proccess.

  // ...
  ob_start();

  echo json_encode($arResult); // only this data should be passed to browser

  $contentLength = ob_get_length();
  header('Connection: close');
  header('Content-Length: ' . $contentLength);

  ob_end_flush();
  ob_flush();
  flush();
  // then performed a long process

(I check the status of the proccess with another ajax-script)

This works fine under apache alone. But I have problems when apache is behind nginx. In this case I get response only when the proccess is completly finished.

nginx settings:

server {
  #...
  proxy_set_header Connection close;

  proxy_pass_header Content-Length;
  #...
}

But I still get Connection keep-alive in FireBug.

How can I get nginx to immediately give a response from apache?

Hope the question is clear.

Thanks.

Was it helpful?

Solution

Have you tried proxy_buffering off in nginx? Not sure it will close the connection but at least the response will be transmited as is to the client. :-)

OTHER TIPS

Nginx does not support any of the flush() methods in PHP when used in a fastcgi or reverse_proxy scheme.

I have tested all of the many proxy_buffering_*, buffer_size_* configurations without success under nginx/0.8.49. It will always wait until the PHP process exits.

If your content is big you have to tune the proxy buffers

client closed prematurely connection while sending to client, in nginx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top