• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

Unexpected results with delayed output

Hi,

I am conducting a little experiment with delayed output:

<HTML>
<HEAD>
<TITLE>PHP Delayed Output Experiment</TITLE>
</HEAD>
<BODY>
<%
     print("Hello PHP World<BR>");
     flush();
     sleep(3);
     print("Hello PHP World<BR>");
     flush();
     sleep(3);
     print("Hello PHP World<BR>");
     print("<HR>");    
%>
</BODY>
</HTML>

I expected that the printed lines would show in my browser window with a 3 second delay, but in fact this code just waits 6 seconds and then shows all output at once.

So now I am wondering isn?t it possible to delay the output this way, or am I just doing something wrong?

Regards,
Benny (PHP newbie)

BTW I am running PHP 4.04 on Win2000/IIS5
0
bvluggen
Asked:
bvluggen
  • 2
1 Solution
 
us111Commented:
yes you can but only with the flush function.
http://www.php.net/manual/en/ref.outcontrol.php

I cannot help you more, never tried
0
 
mubarmejCommented:
From the PHP manual:

"Note: flush() has no effect on the buffering scheme of your webserver or the browser on the client side.

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

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. "

flush will just flush the output in the PHP buffer, but the output is usually also buffered by the server and sometimes by the browsers too.

note: Buffer mains a place to accumelate output and then release it as a larger chunk, for example when you print two small messages, instead of doing all the long process of delivering the output to the user twice, the output is stored in the memory until it reaches a certain size then it is all sent at once.
0
 
bvluggenAuthor Commented:
The link provided by us111 pointed me to the same info as given by mubarmej so that's why I granted the point to us111.

I tested my code in other browsers on windows NS4.7/6 en Opera 5. It runs like expected in these browsers, so on the win platform only MSIE does it's own job of caching and I didn't find a solution yet to overrule this behavier. So any tips on this will be appreciated.

Thanks for your comments.
Benny
0
 
us111Commented:
the problem is there're not too many examples for these functions....
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now