3

I work on a PHP project and I use flush().

I did a lot of search and found that PHP sends long outputs of scripts to the browser in chunk parts and does not send all the huge data when the script terminates.

I want to know the size of this data, I mean how many bytes the output must be for PHP to send them to browser.

6
  • I'm pretty sure the browser has some kind of limit too, before it decides to actually display it. Commented Aug 8, 2012 at 4:17
  • yeh.modern browser must receive 512 byte to display contents but i want to know php limit to auto flush the output to browser(without calling flush() function) Commented Aug 8, 2012 at 4:19
  • php.net/manual/en/… Commented Aug 8, 2012 at 4:26
  • the Description section on the flush() pages has the most information i could find - there is no fixed answer to this. Commented Aug 8, 2012 at 4:26
  • no,php dont use it.in my system output_buffering is off but when i run a script with a loop with 100,000 times the script progressively catch data from php that means php send output in chunk parts not script termination..i know what output_buffering=on do but php without this directive send chunk size output on LARGE scripts Commented Aug 8, 2012 at 4:29

2 Answers 2

4

It's not only PHP that chunks the data; it's actually the job of Apache (or Tomcat etc) to do this. That's why the default is to turn off the "chunking" in PHP and leave it to Apache. Even if you force a flush from PHP, it still can get trapped by Apache. From the manual:

flush() may not be able to override the buffering scheme of your web server and it has no effect on any client-side buffering in the browser. It also doesn't affect PHP's userspace output buffering mechanism. This means you will have to call both ob_flush() and flush() to flush the ob output buffers if you are using those.

There's a Wikipedia article on transfer encoding / chunking: http://en.wikipedia.org/wiki/Chunked_transfer_encoding

Apache gets more complicated with GZIP or deflate encoding; you'll need to hit an apache server as to how you chan configure it.

Sign up to request clarification or add additional context in comments.

Comments

0

i think you are wrong see this code

echo str_repeat(' ',1024);
for($i=0;$i<10;$i++){
echo $i;
flush();
sleep(1);   

if you run it see that every 1 byte sent to browser and print //the str_repeat is for browser buffer for showing data and nothing else

2 Comments

It all depends on your webserver config and browser. Fastest way is to turn on GZIP on your apache and then see what happens.
it's not even a valid PHP code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.