displaying text while page is loading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

    displaying text while page is loading

    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!

  • Dani CS

    #2
    Re: displaying text while page is loading

    yawnmoth wrote:[color=blue]
    > 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';
    > ?>[/color]

    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>
    [color=blue]
    >
    > any help would be appreciated - thanks!
    >[/color]

    Comment

    • yawnmoth

      #3
      Re: displaying text while page is loading


      Dani CS wrote:[color=blue]
      > yawnmoth wrote:[color=green]
      > > 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[/color][/color]
      has[color=blue][color=green]
      > > fully loaded - which is not what i want (i want AAA to appear and[/color][/color]
      then[color=blue][color=green]
      > > 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[/color][/color]
      avail:[color=blue][color=green]
      > >
      > > <?
      > > echo 'AAA<br>';
      > > ob_flush();
      > > flush();
      > > sleep(10);
      > > echo 'BBB';
      > > ?>[/color]
      >
      > Which browser are you using? If you use Internet Explorer this may be[/color]
      [color=blue]
      > 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[/color]
      [color=blue]
      > may need to send extra whitespace before flushing to get those[/color]
      browsers[color=blue]
      > to display the page.
      > </quote>[/color]

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

      Comment

      • Sacs

        #4
        Re: displaying text while page is loading

        yawnmoth wrote:[color=blue]
        > 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!
        >[/color]
        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>';

        Comment

        • Dani CS

          #5
          Re: displaying text while page is loading

          Sacs wrote:[color=blue]
          > yawnmoth wrote:
          >[color=green]
          >> 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!
          >>[/color]
          > 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.[/color]

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

          "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.
          [color=blue]
          >
          > 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>';[/color]


          I think that the original post doesn't want this.

          Comment

          • yawnmoth

            #6
            Re: displaying text while page is loading


            Dani CS wrote:[color=blue]
            > Sacs wrote:[color=green]
            > > yawnmoth wrote:
            > >[/color]
            > <snip>
            >
            > You are wrong. Counterexample available at
            > <http://www-etsi2.ugr.es/web/buscapersonas.p hp3>.[/color]

            another counter example:



            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?
            [color=blue]
            > What the original post requests is a way to make the client update[/color]
            the[color=blue]
            > webpage in the middle of the response, when the connection is still
            > established and data is flowing from the server.[/color]
            yup - that's exactly what i'm wanting to know :)

            Comment

            • Sacs

              #7
              Re: displaying text while page is loading

              Dani CS wrote:
              [color=blue]
              > You are wrong.[/color]

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

              :-)

              Comment

              • Chung Leong

                #8
                Re: displaying text while page is loading

                "yawnmoth" <terra1024@yaho o.com> wrote in message
                news:1103604685 .303195.171710@ f14g2000cwb.goo glegroups.com.. .[color=blue]
                > 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![/color]

                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);



                Comment

                Working...