By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,160 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

displaying text while page is loading

P: n/a
i'm trying to display text while a page is loading using a method
similar to the following:

<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>

in this script, AAA and BBB appear at the same time - when the page has
fully loaded - which is not what i want (i want AAA to appear and then
10 seconds later, BBB to appear). pursuant to the suggestions on
php.net's entry for flush, i've also tried the following to no avail:

<?
echo 'AAA<br>';
ob_flush();
flush();
sleep(10);
echo 'BBB';
?>

any help would be appreciated - thanks!

Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
yawnmoth wrote:
i'm trying to display text while a page is loading using a method
similar to the following:

<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>

in this script, AAA and BBB appear at the same time - when the page has
fully loaded - which is not what i want (i want AAA to appear and then
10 seconds later, BBB to appear). pursuant to the suggestions on
php.net's entry for flush, i've also tried the following to no avail:

<?
echo 'AAA<br>';
ob_flush();
flush();
sleep(10);
echo 'BBB';
?>
Which browser are you using? If you use Internet Explorer this may be
interesting:

<quote src="http://es.php.net/flush">
Some versions of Microsoft Internet Explorer will only start to
display the page after they have received 256 bytes of output, so you
may need to send extra whitespace before flushing to get those browsers
to display the page.
</quote>

any help would be appreciated - thanks!

Jul 17 '05 #2

P: n/a

Dani CS wrote:
yawnmoth wrote:
i'm trying to display text while a page is loading using a method
similar to the following:

<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>

in this script, AAA and BBB appear at the same time - when the page has fully loaded - which is not what i want (i want AAA to appear and then 10 seconds later, BBB to appear). pursuant to the suggestions on
php.net's entry for flush, i've also tried the following to no avail:
<?
echo 'AAA<br>';
ob_flush();
flush();
sleep(10);
echo 'BBB';
?>
Which browser are you using? If you use Internet Explorer this may be

interesting:

<quote src="http://es.php.net/flush">
Some versions of Microsoft Internet Explorer will only start to
display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.
</quote>


i've tried both IE and firefox (for windows) and get the same results...

Jul 17 '05 #3

P: n/a
yawnmoth wrote:
i'm trying to display text while a page is loading using a method
similar to the following:

<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>

in this script, AAA and BBB appear at the same time - when the page has
fully loaded - which is not what i want (i want AAA to appear and then
10 seconds later, BBB to appear). pursuant to the suggestions on
php.net's entry for flush, i've also tried the following to no avail:

<?
echo 'AAA<br>';
ob_flush();
flush();
sleep(10);
echo 'BBB';
?>

any help would be appreciated - thanks!

Errr, you cant. A browser-webserver connection is stateless. The
browser will wait until the whole page has arrived before displaying
it, at which stage the web server and your php have allready forgotten
about you.

You *may* be able to do something using a http refresh in the <head> of
the page e.g.

page1.php:
echo '
<head>
<META HTTP-EQUIV=Refresh CONTENT="10; URL=http:page2.php">
</head>
<body>
AAA<br>
';

page2.php:
echo 'BBB<br>';
Jul 17 '05 #4

P: n/a
Sacs wrote:
yawnmoth wrote:
i'm trying to display text while a page is loading using a method
similar to the following:

<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>

in this script, AAA and BBB appear at the same time - when the page has
fully loaded - which is not what i want (i want AAA to appear and then
10 seconds later, BBB to appear). pursuant to the suggestions on
php.net's entry for flush, i've also tried the following to no avail:

<?
echo 'AAA<br>';
ob_flush();
flush();
sleep(10);
echo 'BBB';
?>

any help would be appreciated - thanks!
Errr, you cant. A browser-webserver connection is stateless. The
browser will wait until the whole page has arrived before displaying it,
at which stage the web server and your php have allready forgotten about
you.


You are wrong. Counterexample available at
<http://www-etsi2.ugr.es/web/buscapersonas.php3>.

"stateless" means that the server is aware of the client only during the
request-response time, but the rest of the time the client is disconnected.

What the original post requests is a way to make the client update the
webpage in the middle of the response, when the connection is still
established and data is flowing from the server. This is perfectly
possible, if the browser is capable.

You *may* be able to do something using a http refresh in the <head> of
the page e.g.

page1.php:
echo '
<head>
<META HTTP-EQUIV=Refresh CONTENT="10; URL=http:page2.php">
</head>
<body>
AAA<br>
';

page2.php:
echo 'BBB<br>';

I think that the original post doesn't want this.
Jul 17 '05 #5

P: n/a

Dani CS wrote:
Sacs wrote:
yawnmoth wrote:
<snip>

You are wrong. Counterexample available at
<http://www-etsi2.ugr.es/web/buscapersonas.php3>.


another counter example:

http://www.proxyelite.org/phpBB2/proxy_list_check.php

also, how would a browser be able to distinguish between a slow server
or a really big webpage and one that has simply run the sleep command?
the first two don't require the whole page be loaded before it displays
any part of it, so why should it do so when i use sleep?
What the original post requests is a way to make the client update the webpage in the middle of the response, when the connection is still
established and data is flowing from the server.

yup - that's exactly what i'm wanting to know :)

Jul 17 '05 #6

P: n/a
Dani CS wrote:
You are wrong.


Ok, I sit corrected. I blame the mother of all hangovers, my brain
isn't exactly engaged at the moment...

:-)
Jul 17 '05 #7

P: n/a
"yawnmoth" <te*******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
i'm trying to display text while a page is loading using a method
similar to the following:

<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>

in this script, AAA and BBB appear at the same time - when the page has
fully loaded - which is not what i want (i want AAA to appear and then
10 seconds later, BBB to appear). pursuant to the suggestions on
php.net's entry for flush, i've also tried the following to no avail:

<?
echo 'AAA<br>';
ob_flush();
flush();
sleep(10);
echo 'BBB';
?>

any help would be appreciated - thanks!


All browsers buffer incoming data. Rendering will only happen after a
certain amount of data has been read (usually a few Ks). If a browser redraw
the page with every few bytes of data then your screen would constantly
flicker.

To make the browser update the page, send a bunch of comment tags after the
actual contents:

echo str_repeat("<!-- Agent Smith -->", 1000);

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.