title: How to gracefully tell client the transmission is finished so the browser will display the page immediately?
body: <p>Greeting guys,</p>
  
  <p>I'm working on my php framework. It has a response manager to wrapper php's header, cookie, and buffer functions. I use this to send result page to user.</p>
  
  <p>However, even the page header and contents already be sent by using ob_start -> ob_end_flush -> flush, the browser still hanging and wait for script to complete.</p>
  
  <p>It cause problems when i want to do some slow job like update current user's session or just send a mail or upload something. User will have to wait until everything done, even they already have the whole page including header.</p>
  
  <p><em><strong>What I want to know is, how to make browser know the page is completely loaded, so it can display the page right now?</em></strong></p>
  
  <p>Thank you!</p>
  
  <p>////////////////////////////  Abandoned Solutions  ////////////////////////////</p>
  
  <p><strong>Abandoned Solution 1</strong></p>
  
  <p>In the past, i usually use the combination of ob_start -> ob_end_flush -> ob_flush -> flush to <em>fix</em> this problem, it seems will like this:</p>
  
  <pre><code>function send($content) {
      ob_start();
  
      echo $content;
  
      ob_end_flush();
      ob_flush();
      flush();
  
      return true;
  }
  </code></pre>
  
  <p><strong>But</strong> the ob_flush will throw a E_NOTICE says it have "No buffer to flush". I don't want to fix this by just mute this E_NOTICE (<em>and in fact, in my framework, there is no way to mute any error</em>). So this is not the way to solve this problem.</p>
  
  <p><strong>Abandoned Solution 2</strong></p>
  
  <p>I also try to close connection after content sent, code will like this:</p>
  
  <pre><code>function send($content) {
      ob_start();
  
      header('Connection: close');
  
      echo $content;
  
      ob_end_flush();
  
      flush();
  
      return true;
  }
  </code></pre>
  
  <p>It can solve the problem with out any error, but it bring another problem: Seems client's connection will be close after page received, and when they want to open another page, they have to reconnect. This will generate extra load on network.</p>
  
  <p><strong>Abandoned Solution 3</strong></p>
  
  <p>Yeah, some people suggested me to use fastcgi, and use fastcgi_finish_request(); But i want to make my code more compatible between environments, so it actually not a option.</p>