Progress indicators on a page...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • no@emails.thx

    Progress indicators on a page...?

    Hi

    I have a PHP script that updates a very large table and in the code I
    echo some text to show the progress of the update but the text only
    appears when the page has finished displaying.

    Is there any way (through html headers?) to force the page to update
    in real time, while the PHP script is still executing?

    I have seen similar thngs on webmin pages when it is downloading
    updates and it is nothing fancy (graphics etc) - just text.

    Thanks
    Chris R.
  • Henrik Hansen

    #2
    Re: Progress indicators on a page...?

    no@emails.thx writes:
    [color=blue]
    > Hi
    >
    > I have a PHP script that updates a very large table and in the code I
    > echo some text to show the progress of the update but the text only
    > appears when the page has finished displaying.
    >
    > Is there any way (through html headers?) to force the page to update
    > in real time, while the PHP script is still executing?
    >
    > I have seen similar thngs on webmin pages when it is downloading
    > updates and it is nothing fancy (graphics etc) - just text.[/color]

    the php function flush() does the trick

    --
    Henrik Hansen

    Comment

    • Andy Jeffries

      #3
      Re: Progress indicators on a page...?

      On Tue, 20 Jun 2006 13:07:13 +0000, no wrote:[color=blue]
      > I have a PHP script that updates a very large table and in the code I echo
      > some text to show the progress of the update but the text only appears
      > when the page has finished displaying.
      >
      > Is there any way (through html headers?) to force the page to update in
      > real time, while the PHP script is still executing?[/color]

      I'd say go with AJAX. It's really not hard to learn, and as it's a
      non-essential function if people don't have it, they can do without.

      You could then provide an estimate of the time to completion (using number
      of rows complete, number to be completed and number completed in last
      second).

      Cheers,


      Andy

      --
      Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
      http://www.gphpedit.org | PHP editor for Gnome 2
      http://www.andyjeffries.co.uk | Personal site and photos

      Comment

      • Jerry Stuckle

        #4
        Re: Progress indicators on a page...?

        no@emails.thx wrote:[color=blue]
        > Hi
        >
        > I have a PHP script that updates a very large table and in the code I
        > echo some text to show the progress of the update but the text only
        > appears when the page has finished displaying.
        >
        > Is there any way (through html headers?) to force the page to update
        > in real time, while the PHP script is still executing?
        >
        > I have seen similar thngs on webmin pages when it is downloading
        > updates and it is nothing fancy (graphics etc) - just text.
        >
        > Thanks
        > Chris R.[/color]

        As Henrik indicated, flush() works. You may also need to call ob_flush().

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • no@emails.thx

          #5
          Re: Progress indicators on a page...?

          On Tue, 20 Jun 2006 15:49:03 GMT, Andy Jeffries
          <news@andyjeffr ies.co.uk> wrote:
          [color=blue]
          >On Tue, 20 Jun 2006 13:07:13 +0000, no wrote:[color=green]
          >> I have a PHP script that updates a very large table and in the code I echo
          >> some text to show the progress of the update but the text only appears
          >> when the page has finished displaying.
          >>
          >> Is there any way (through html headers?) to force the page to update in
          >> real time, while the PHP script is still executing?[/color]
          >
          >I'd say go with AJAX. It's really not hard to learn, and as it's a
          >non-essential function if people don't have it, they can do without.
          >
          >You could then provide an estimate of the time to completion (using number
          >of rows complete, number to be completed and number completed in last
          >second).[/color]

          Thanks Andy

          I have had a look at Ajax ... a bit daunting but I might give it a
          try, as the site I am developing would benefit from the look and feel
          of a true application.

          Chris R.

          Comment

          • no@emails.thx

            #6
            Re: Progress indicators on a page...?

            On Tue, 20 Jun 2006 12:32:23 -0400, Jerry Stuckle
            <jstucklex@attg lobal.net> wrote:
            [color=blue]
            >no@emails.th x wrote:[color=green]
            >> Hi
            >>
            >> I have a PHP script that updates a very large table and in the code I
            >> echo some text to show the progress of the update but the text only
            >> appears when the page has finished displaying.
            >>
            >> Is there any way (through html headers?) to force the page to update
            >> in real time, while the PHP script is still executing?
            >>
            >> I have seen similar thngs on webmin pages when it is downloading
            >> updates and it is nothing fancy (graphics etc) - just text.
            >>
            >> Thanks
            >> Chris R.[/color]
            >
            >As Henrik indicated, flush() works. You may also need to call ob_flush().[/color]

            Hi Henrik & Jerry

            I tried ob_flush() followed by flush(), as suggested but it dodn't
            make a difference - still got a blank page for 5 minutes than SPLAT! a
            full page listing all the imported records.

            Another poster on a different group suggested it might be because I
            use nested tables to arrange the content on the page. Apparently
            browsers often refuse to display the cells until the </table> is
            received.

            With that in mind I might look at using Ajax or just reworking the
            pages using CSS to position blocks of content on the page. :o)

            Cheers, Chris R.

            Comment

            • Chuck Anderson

              #7
              Re: Progress indicators on a page...?

              no@emails.thx wrote:[color=blue]
              > On Tue, 20 Jun 2006 12:32:23 -0400, Jerry Stuckle
              > <jstucklex@attg lobal.net> wrote:
              >
              >[color=green]
              >> no@emails.thx wrote:
              >>[color=darkred]
              >>> Hi
              >>>
              >>> I have a PHP script that updates a very large table and in the code I
              >>> echo some text to show the progress of the update but the text only
              >>> appears when the page has finished displaying.
              >>>
              >>> Is there any way (through html headers?) to force the page to update
              >>> in real time, while the PHP script is still executing?
              >>>
              >>> I have seen similar thngs on webmin pages when it is downloading
              >>> updates and it is nothing fancy (graphics etc) - just text.
              >>>
              >>> Thanks
              >>> Chris R.
              >>>[/color]
              >> As Henrik indicated, flush() works. You may also need to call ob_flush().
              >>[/color]
              >
              > Hi Henrik & Jerry
              >
              > I tried ob_flush() followed by flush(), as suggested but it dodn't
              > make a difference - still got a blank page for 5 minutes than SPLAT! a
              > full page listing all the imported records.
              >
              > Another poster on a different group suggested it might be because I
              > use nested tables to arrange the content on the page. Apparently
              > browsers often refuse to display the cells until the </table> is
              > received.
              >
              > With that in mind I might look at using Ajax or just reworking the
              > pages using CSS to position blocks of content on the page. :o)
              >
              > Cheers, Chris R.
              >[/color]
              Not Php, but .....

              If you want to use an animated gif as a "dumb" progress bar, here is
              some css that does it.
              http://www.cssplay.co.uk/menu/start_gif.html (using a.hover and a.click)

              You can also use Javascript to start and stop an animated gif (let me
              know if you want to see this method).

              Or another Javascript method:


              --
              *************** **************
              Chuck Anderson • Boulder, CO

              Everyone's journey should be different,
              so that we all are enriched
              in new and endless ways
              *************** **************

              Comment

              • Jerry Stuckle

                #8
                Re: Progress indicators on a page...?

                no@emails.thx wrote:[color=blue]
                > On Tue, 20 Jun 2006 12:32:23 -0400, Jerry Stuckle
                > <jstucklex@attg lobal.net> wrote:
                >
                >[color=green]
                >>no@emails.t hx wrote:
                >>[color=darkred]
                >>>Hi
                >>>
                >>>I have a PHP script that updates a very large table and in the code I
                >>>echo some text to show the progress of the update but the text only
                >>>appears when the page has finished displaying.
                >>>
                >>>Is there any way (through html headers?) to force the page to update
                >>>in real time, while the PHP script is still executing?
                >>>
                >>>I have seen similar thngs on webmin pages when it is downloading
                >>>updates and it is nothing fancy (graphics etc) - just text.
                >>>
                >>>Thanks
                >>>Chris R.[/color]
                >>
                >>As Henrik indicated, flush() works. You may also need to call ob_flush().[/color]
                >
                >
                > Hi Henrik & Jerry
                >
                > I tried ob_flush() followed by flush(), as suggested but it dodn't
                > make a difference - still got a blank page for 5 minutes than SPLAT! a
                > full page listing all the imported records.
                >
                > Another poster on a different group suggested it might be because I
                > use nested tables to arrange the content on the page. Apparently
                > browsers often refuse to display the cells until the </table> is
                > received.
                >
                > With that in mind I might look at using Ajax or just reworking the
                > pages using CSS to position blocks of content on the page. :o)
                >
                > Cheers, Chris R.[/color]

                Chris,

                Ah, nested tables. That does add a new dimension to the problem.

                I use ob_lush() and flush() when I have long-running tasks. But I generally
                don't like to use tables for layout, either. It should work a lot better with CSS.


                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Andy Jeffries

                  #9
                  Re: Progress indicators on a page...?

                  On Thu, 22 Jun 2006 17:54:44 +0000, no wrote:[color=blue]
                  > I have had a look at Ajax ... a bit daunting but I might give it a try, as
                  > the site I am developing would benefit from the look and feel of a true
                  > application.[/color]

                  Hi Chris,

                  Send me an email if you like. I sent a few emails recently to another guy
                  of this group explaining AJAX and how to use it easily from PHP. I can
                  forward those emails to you if you like (removing any parts that would
                  identify the site he's working on).

                  Cheers,


                  Andy


                  --
                  Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
                  http://www.gphpedit.org | PHP editor for Gnome 2
                  http://www.andyjeffries.co.uk | Personal site and photos

                  Comment

                  • the DtTvB

                    #10
                    Re: Progress indicators on a page...?

                    I have one, without using AJAX.

                    1. Put this code in the header:
                    <div id="liveProgres s"></div>

                    2. In your PHP code, add this function:
                    function setProgress($x) {
                    echo "<script type=\"text/javascript\">"
                    . "document.getEl ementById('live Progress').inne rHTML = '$x';"
                    . "</script>";
                    flush();
                    }

                    3. In your loop, type some code like this:
                    setProgress("Lo ading... ???%");

                    Edit message above to whatever you want.

                    Note that calling too much times of setProgresss function may extremely
                    slowdown client's browser and eats huge amount of bandwidth. I
                    recommend to update status every 50-100 loop.

                    ------------------------------------------------
                    // Example Code:
                    <html><head><ti tle>Progress Test</title></head><body>
                    <div id="liveProgres s"></div>
                    <hr /><?php
                    function setProgress($x) {
                    echo "<script type=\"text/javascript\">"
                    . "document.getEl ementById('live Progress').inne rHTML = '$x';"
                    . "</script>";
                    flush();
                    }
                    $max = 7;
                    for ($i = 0; $i < $max; $i ++) {
                    echo 'Loop #' . ($i + 1) . ' of ' . $max . '<br />';
                    setProgress('Lo ading...' . round(($i / $max) * 100) . '%');
                    sleep(1);
                    }
                    setProgress('Fi nished!!');
                    ?>
                    </body></html>

                    Comment

                    Working...