Web Hosting Talk







View Full Version : Progress bar in PHP


combs
08-25-2002, 10:21 AM
I need a script for showing progress bar in PHP while I process my database records. Any ideas...?

PC configuration: windows xp, apache and php 4.0.6 and php is not as a cgi to apache but a module..

Omair Haroon
08-25-2002, 11:33 AM
Well, I remember there was an article on hotscripts.com. Give me a minute and I would post the article URL over here. :)

Omair Haroon
08-25-2002, 11:40 AM
Here it is:
http://www.hotscripts.com/Detailed/13962.html

Though in Javascript, but you can use it in conjunction with PHP with a little bit of creativity. Give me a shout if you need help! :)

Omair Haroon
08-25-2002, 11:42 AM
Here is yet another URL with more results:

http://www.google.com/search?q=progress+bar+in+PHP&hl=en&lr=&ie=UTF-8&newwindow=1&safe=off&start=10&sa=N


--Omair

interactive
08-25-2002, 11:51 AM
since php is server side its extremly hard to do it. but you could try.

Omair Haroon
08-25-2002, 12:04 PM
Actually not that hard :)

Studio64
08-25-2002, 05:31 PM
Well... Pretty much any progress bar that would be displayed would simply be faking the progress that is taking place.

PHP is a server side scripting language...

Follow the progress of a PHP script

Page Request to server
Server Parses Page
-- Calls DB if needed in script
Page is outputted to browser

There is no page->Server interaction in a PHP script.

If I have a page that would do maybe 30,000 alterations to a DB that page would only display to the browser after it's been completely parsed by the server. So the page would only display after the 30,000 DB calls have been completed. I can't picture in my head a script that alters the browser content at every X DB manipulations.

The Prohacker
08-25-2002, 05:41 PM
Originally posted by Studio64
If I have a page that would do maybe 30,000 alterations to a DB that page would only display to the browser after it's been completely parsed by the server. So the page would only display after the 30,000 DB calls have been completed. I can't picture in my head a script that alters the browser content at every X DB manipulations.


Not really, you can have the page output an update during the mysql updates...


db initilze
progress start
db insert
update progress bar 1%
db insert
update progressbar 3%
dbinsert
etc..


So... just echo out the update to browser and do the next db insert...

The Prohacker
08-25-2002, 06:16 PM
For a status bar that would allow you to update like I said above...

http://webfx.eae.net/dhtml/statusbar/statusbar.html

Ahmad
08-25-2002, 09:34 PM
Originally posted by The Prohacker



Not really, you can have the page output an update during the mysql updates...


db initilze
progress start
db insert
update progress bar 1%
db insert
update progressbar 3%
dbinsert
etc..


So... just echo out the update to browser and do the next db insert...


There is actually a problem with this solution ..

PHP by default buffers the output of the script until the buffer is full before sending it to the client, to achieve maximum network utilization. This buffering is also done at the Apache level, and the OS level. You can probably bypass all these buffers by calling flush(); ..

However, there are still other buffers you don't have control over, like buffering at a proxy server.

All-in-all, this is a nice method, but unreliable most of the time.

An alternative solution would be refershing the page for each chunk of the updates. Say you have 33,000 records to update, so what you do is make 1000 updates with every call, so you start by the first 1000, stop execution, return an HTML page that will display a progress bar and redirect to user to a URL that will cause the update of the next 1000 records, until you finish all the processing.

You can also use a combination of JavaScript and frames to achieve a nice looking progress bar.

edit: check the man page for flush(), there is nice information about this issue. Also in the comments, somebody talks particularly about how he made a progress bar:

http://www.php.net/manual/en/function.flush.php

archie2
08-26-2002, 03:16 AM
That was a wonderful link provided by Ahmed. I will also try. Thank you

combs
08-27-2002, 01:19 PM
Thank you all for your feedback.
I have not made it yet but I am in the process of making it. It was really a great help.