[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Unexpected results with delayed output

Posted on 2001-06-08
4
Medium Priority
?
425 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 150 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

656 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