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

Progress indicators on a page...?

P: n/a
no
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.
Jun 20 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
no@emails.thx writes:
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.


the php function flush() does the trick

--
Henrik Hansen
Jun 20 '06 #2

P: n/a
On Tue, 20 Jun 2006 13:07:13 +0000, no wrote:
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'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

Jun 20 '06 #3

P: n/a
no@emails.thx wrote:
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.


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.
js*******@attglobal.net
==================
Jun 20 '06 #4

P: n/a
no
On Tue, 20 Jun 2006 15:49:03 GMT, Andy Jeffries
<ne**@andyjeffries.co.uk> wrote:
On Tue, 20 Jun 2006 13:07:13 +0000, no wrote:
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'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).


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.
Jun 22 '06 #5

P: n/a
no
On Tue, 20 Jun 2006 12:32:23 -0400, Jerry Stuckle
<js*******@attglobal.net> wrote:
no@emails.thx wrote:
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.


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


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.
Jun 22 '06 #6

P: n/a
no@emails.thx wrote:
On Tue, 20 Jun 2006 12:32:23 -0400, Jerry Stuckle
<js*******@attglobal.net> wrote:

no@emails.thx wrote:
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.

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


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.

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:
http://www.irt.org/script/1225.htm

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*****************************
Jun 22 '06 #7

P: n/a
no@emails.thx wrote:
On Tue, 20 Jun 2006 12:32:23 -0400, Jerry Stuckle
<js*******@attglobal.net> wrote:

no@emails.thx wrote:
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.


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

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.


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.
js*******@attglobal.net
==================
Jun 23 '06 #8

P: n/a
On Thu, 22 Jun 2006 17:54:44 +0000, no wrote:
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.


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

Jun 23 '06 #9

P: n/a
I have one, without using AJAX.

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

2. In your PHP code, add this function:
function setProgress($x) {
echo "<script type=\"text/javascript\">"
. "document.getElementById('liveProgress').inner HTML = '$x';"
. "</script>";
flush();
}

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

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><title>Progress Test</title></head><body>
<div id="liveProgress"></div>
<hr /><?php
function setProgress($x) {
echo "<script type=\"text/javascript\">"
. "document.getElementById('liveProgress').inner HTML = '$x';"
. "</script>";
flush();
}
$max = 7;
for ($i = 0; $i < $max; $i ++) {
echo 'Loop #' . ($i + 1) . ' of ' . $max . '<br />';
setProgress('Loading...' . round(($i / $max) * 100) . '%');
sleep(1);
}
setProgress('Finished!!');
?>
</body></html>

Jun 23 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.