Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just keep in mind what @Wrikken said, this is not recommended.</p> <p>So I was thinking, everything you're doing seems to be right. I copied your setup and tried. I faced same problem. I executed the script from command line, it worked.</p> <p>Then I had to do the last test, Wireshark. Following the first couple of packets it was clear that the server is sending everything correctly, so it had to be the browser’s buffer.</p> <p>So I tried send some data before the loop, well guess what? It worked!</p> <p>Here you go:</p> <pre><code>&lt;?php ini_set('output_buffering','off'); ini_set('zlib.output_compression', 0); echo str_repeat(" ", 1024), "\n"; for($i=0;$i&lt;6;$i++) { echo $i."&lt;br /&gt;\n"; ob_flush(); flush(); sleep(1); } ?&gt; </code></pre> <p>I'm not sure about the application you have in mind, but this is clearly not a good idea, I highly recommend that you look into other options.</p> <p><strong>Update:</strong> After a lengthy Google search I found <a href="http://gtmetrix.com/specify-a-character-set-early.html" rel="nofollow">this</a> and <a href="https://developers.google.com/speed/docs/best-practices/rendering" rel="nofollow">this</a></p> <blockquote> <p>Because a browser cannot correctly render a page without knowing how to construct the page's characters, most browsers buffer a certain number of bytes before executing any JavaScript or drawing the page</p> </blockquote> <p>And</p> <blockquote> <p>To avoid these delays, you should always specify the character encoding as early as possible, for any HTML document larger than 1 KB (<strong>1024 bytes</strong>, to be precise, which is the maximum buffer limit used by any of the browsers we have tested).</p> </blockquote> <p>So I tried to send the charset first instead of filling the buffer: (and it worked)</p> <pre><code>&lt;?php ini_set('output_buffering','off'); ini_set('zlib.output_compression', 0); //echo str_repeat(" ", 1024), "\n"; header('Content-Type: text/html; charset=iso-8859-1'); //Note that it shoudn't matter which charset you send for($i=0;$i&lt;6;$i++) { echo $i."&lt;br /&gt;\n"; ob_flush(); flush(); sleep(1); } ?&gt; </code></pre> <p><strong>So why was it working with the first server but not the second?</strong></p> <p>Most likely it's because your first server is sending the charset with the header while the second one isn't.</p> <p>In your case, however, I'd make the following changes</p> <pre><code>&lt;?php ini_set('output_buffering','off'); ini_set('zlib.output_compression', 0); //Plain text MIME type since you'll use for logging purposes //and if you run it from CLI, you can ignore the whole header line header('Content-Type: text/plain; charset=iso-8859-1'); for($i=0;$i&lt;6;$i++) { //No need to echo &lt;br /&gt; once you'll run it from CLI echo $i."\n"; ob_flush(); flush(); sleep(1); } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload