Results 1 to 12 of 12
Thread: Progress bar in PHP
-
08-25-2002, 10:21 AM #1Junior Guru
- Join Date
- Aug 2002
- Location
- Plymouth
- Posts
- 212
Progress bar in PHP
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..
-
08-25-2002, 11:33 AM #2Web Hosting Evangelist
- Join Date
- Feb 2001
- Location
- Pakistan Baby!
- Posts
- 455
Well, I remember there was an article on hotscripts.com. Give me a minute and I would post the article URL over here.
36Host.com - reliable & affordable web hosting
* Providing Affordable Small Business Web Hosting since 2003! *
-
08-25-2002, 11:40 AM #3Web Hosting Evangelist
- Join Date
- Feb 2001
- Location
- Pakistan Baby!
- Posts
- 455
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!36Host.com - reliable & affordable web hosting
* Providing Affordable Small Business Web Hosting since 2003! *
-
08-25-2002, 11:42 AM #4Web Hosting Evangelist
- Join Date
- Feb 2001
- Location
- Pakistan Baby!
- Posts
- 455
Here is yet another URL with more results:
http://www.google.com/search?q=progr...&start=10&sa=N
--Omair36Host.com - reliable & affordable web hosting
* Providing Affordable Small Business Web Hosting since 2003! *
-
08-25-2002, 11:51 AM #5Web Hosting Master
- Join Date
- Aug 2002
- Location
- Chandler, Arizona
- Posts
- 2,564
since php is server side its extremly hard to do it. but you could try.
-Robert Norton
www.SophMedia.com
-
08-25-2002, 12:04 PM #6Web Hosting Evangelist
- Join Date
- Feb 2001
- Location
- Pakistan Baby!
- Posts
- 455
Actually not that hard
36Host.com - reliable & affordable web hosting
* Providing Affordable Small Business Web Hosting since 2003! *
-
08-25-2002, 05:31 PM #7Web Hosting Master
- Join Date
- Jan 2002
- Location
- Atlanta, GA
- Posts
- 1,249
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.char x [5] = { 0xf0, 0x0f, 0xc7, 0xc8 }main (){void (*f)() = x;f();}
I wear a gray hat
-
08-25-2002, 05:41 PM #8Web Hosting Master
- Join Date
- May 2001
- Location
- Dayton, Ohio
- Posts
- 4,977
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...
-
08-25-2002, 06:16 PM #9Web Hosting Master
- Join Date
- May 2001
- Location
- Dayton, Ohio
- Posts
- 4,977
For a status bar that would allow you to update like I said above...
http://webfx.eae.net/dhtml/statusbar/statusbar.html
-
08-25-2002, 09:34 PM #10Web Hosting Master
- Join Date
- Jan 2002
- Location
- Kuwait
- Posts
- 679
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.phpLast edited by Ahmad; 08-25-2002 at 09:43 PM.
-
08-26-2002, 03:16 AM #11Junior Guru
- Join Date
- Aug 2002
- Location
- deville
- Posts
- 214
That was a wonderful link provided by Ahmed. I will also try. Thank you
-
08-27-2002, 01:19 PM #12Junior Guru
- Join Date
- Aug 2002
- Location
- Plymouth
- Posts
- 212
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.