Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Aug 2002
    Location
    Plymouth
    Posts
    212

    Lightbulb 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..

  2. #2
    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! *

  3. #3
    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! *

  4. #4
    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


    --Omair
    36Host.com - reliable & affordable web hosting
    * Providing Affordable Small Business Web Hosting since 2003! *

  5. #5
    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

  6. #6
    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! *

  7. #7
    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

  8. #8
    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...

  9. #9
    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

  10. #10
    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.php
    Last edited by Ahmad; 08-25-2002 at 09:43 PM.
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  11. #11
    Join Date
    Aug 2002
    Location
    deville
    Posts
    214

    *

    That was a wonderful link provided by Ahmed. I will also try. Thank you

  12. #12
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •