2

Trying to close connection with browser and keep php process alive, but browser waiting for the process end. I think that the problem is in real content length. There is my code in ZF1:

ob_end_clean();
header("Connection: close");
ignore_user_abort(true);
ob_start();
echo Zend_Controller_Front::getInstance()->getResponse()->getBody();
$size = ob_get_length();
header("Content-Length: $size");
Zend_Session::writeClose();
ob_end_flush();
ob_flush();
flush();

sleep(5); // for example

So browser keeps connection for 5 sec. Variable $size value is equal with content characters count. When trying to print empty content and set $size variable to 0, then browser work as expected and don't wait for 5 seconds. Could you please share your ideas what the problem can be?

Alex Rešatniak
  • 443
  • 1
  • 5
  • 9
  • The expected behaviour for this snippet would be that the browser wait for 5 seconds, and then closes the connection. But if you tell a browser that you are sending it `0` bytes of data, then why should it keep listening? It already knows nothing will come, and any sensible browser will thus close the connection. – CerebralFart Feb 23 '16 at 23:17
  • But I send the headers to browser with connection: close, content-length and content, which length is equal with header content-length. Btw, it works (mean don't wait) on my local machine, but doesn't work on the real server. – Alex Rešatniak Feb 23 '16 at 23:20
  • If it works on your local machine, but not on the real server, then there is a difference in the config. Please make sure that those are identical. – CerebralFart Feb 23 '16 at 23:25

0 Answers0