Solved

Unexpected results with delayed output

Posted on 2001-06-08
4
413 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now