Solved

Unexpected results with delayed output

Posted on 2001-06-08
4
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 look for a specific file type in a local or remote server directory using PHP.

688 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