Solved

Unexpected results with delayed output

Posted on 2001-06-08
4
414 Views
Last Modified: 2010-08-05
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
Comment
Question by:bvluggen
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
us111 earned 50 total points
ID: 6169754
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
 
LVL 1

Expert Comment

by:mubarmej
ID: 6170475
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
 

Author Comment

by:bvluggen
ID: 6173173
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
 
LVL 8

Expert Comment

by:us111
ID: 6173791
the problem is there're not too many examples for these functions....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now