Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update a progress bar during a long loop?

How can I update a progress bar (html), during a long loop (php -- database export/import mysqli)

I don't want to use a file or database for storing temporary values or progression of the loop as that causes too many IO's to be used (and in the case of file based solution, the client ends up often reading the file before the data has been written)

I was considering some event type situation however output buffering takes too long to update the display.

Second, I was considering some methods others have imposed of spitting out a javascript to the browser, but that ends up in way too much HTML being output (aka, 1,000,000+ records being dumped).

Basically, I am open to fresh ideas on how I can update the progress bar in a web-browser while some really long process is happening in PHP (this is not file_upload stuff -- I realize there are extensions for PHP which allow for getting the progress, however there doesn't seem to be anything for getting the progress of a server loop).

Any ideas ?? --- i really don't want to stray from PHP/JavaScript/HTML to other platforms such as node.js / cocoa / etc.

like image 414
Kraang Prime Avatar asked Nov 02 '22 01:11

Kraang Prime


1 Answers

You could flush your content as your script´s execution progress.

Here are some useful links to good code samples that may solve your problem:

  • http://spidgorny.blogspot.com.br/2012/02/progress-bar-for-lengthy-php-process.html
  • http://w3shaman.com/article/php-progress-bar-script
  • http://pastebin.com/KSxjC01r
  • http://www.php.net/manual/function.flush.php

You could obtaing other ideas in this topic here: Show progress for long running PHP script

like image 122
Marcelo Bezerra bovino Avatar answered Nov 09 '22 09:11

Marcelo Bezerra bovino