4 Replies - 570 Views - Last Post: 14 December 2011 - 05:25 AM Rate Topic: -----

#1 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

flush()

Posted 28 October 2011 - 01:31 AM

Quick question about how to properly use flush() / ob_flush()

I had a look at some examples from Google, but none of them seem to work. For example one of them said that if you do:

<HTML>
 <BODY>
 This page is loading.<br />
<?php flush(); sleep(2); ?>
 Almost there...<br />
<?php flush(); sleep(2); ?>
 Done.<br />
 </BODY>
 </HTML>



The pieces of text would get flushed out in turn, but when I try it, they just all get printed together at the end, like normal.

I tried various different methods of that, but I can only ever get it to print all the output together when everything has finished.

Could someone point me to/provide me with an example that actually works, so I can see how to use them properly?

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: flush()

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,261
  • Joined: 08-June 10

Re: flush()

Posted 28 October 2011 - 02:47 AM

Quote

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.

Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.

Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client.

Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the </table> tag of the outermost table is seen.

Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.


Id say some of that applies.
Was This Post Helpful? 0
  • +
  • -

#3 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: flush()

Posted 28 October 2011 - 03:10 AM

Already read that and was still unsure, that's why I asked here.
Was This Post Helpful? 0
  • +
  • -

#4 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: flush()

Posted 29 October 2011 - 11:46 AM

I would look into ob_start() and ob_end_flush()

I may not be exact, but I think that the ob_flush is used for timing and running functions on all output before displaying.

If you ran your script from command line, it would do what you think it will

This post has been edited by VolcomMky: 29 October 2011 - 11:49 AM

Was This Post Helpful? 0
  • +
  • -

#5 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: flush()

Posted 14 December 2011 - 05:25 AM

Eventually managed to get it working, by doing:

function flushPage()
{
    ob_end_flush(); 
    flush();
    ob_start();
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1