1

I got trouble with web browsers buffering (not chaching).

I call this php script :

sleep(5);
echo '1st step';
echo (str_repeat(' ',256));
sleep(5);
echo '<br />';
echo '2nd step';

output buffer is disabled on php (we will confirm that later)

when calling this script with both Chromium 12 and Firefox 5 I got this result :

the 'waiting' animated circle (the grey one) runs during ~5sec then the 'transferring' animated circle (the orange one) runs during ~5sec and finally i have the whole result displayed.

My initial goal was, as you expect, to wait 5sec, then see "1st step" displayed, wait 5sec again and then see "2nd step" displayed.

clues

  • php or apache doesn't buffer anything as the animated circle switch from 'waiting' to 'recieving' after 5sec (so the browser did recieve something from the "1st step" echo !)

    • I tried to set Firefox Cache size to 0 so the cache mechanism would be bypassed.. but still no working.

    • I read that some browser may wait until they recieve 256 bytes before they start display the content. That's why i added "echo (str_repeat(' ',256))".. but it doesn't solve anything.

    • I also tried to set network.buffer.cache.count and network.buffer.cache.size options at 0 in firefox about:config, i don't know if those option was rellated to my problem but it is still not working..

Any idea ?

Thanks,

maigre
  • 133
  • 2
  • 10
  • I believe that 256 number needs to be 512. Or you need a meta tag or HTTP header declaring the charset. The cache settings you're messing with have nothing to do with buffering of HTML; I strongly recommend setting the buffer cache count and size back to defaults, since that's for necko's internal memory buffer cache. – Boris Zbarsky Aug 03 '11 at 04:33
  • You are right ! my initial message was just too short.. Thanks ! (how do i set your response as the good one ? and how do i close the question ? i m not familiar with this forum) – maigre Aug 03 '11 at 11:16
  • There should be an "accept" button somewhere on the question, I think. That's how you both set my response as the good one and close the question. I've never tried actually asking a question, so don't know for sure. ;) – Boris Zbarsky Aug 03 '11 at 13:04

1 Answers1

4

Oh, I guess I need to make the answer an answer, not a comment, so you can accept it.

The HTML5 charset sniffing buffer size is 512 bytes. So the response needs to either have 512 bytes of padding or set a charset (via <meta> tag or HTTP header).

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55