I was wondering how I could go about making a progress bar for parsing HTML data. Essentially the user searches something and I parse another website. I tried doing it with getting the amount of objects found in an array then dividing 100 by it, and getting the current one in a for loop and multiplying it by 100/total. Then I would update a text file with the value. Then update the progress bar with that value. However, I want a more efficient way to do it. Also it has to be unique to each user. Thanks.
I was wondering how I could go about making a progress bar for parsing HTML data. Essentially the user searches something and I parse another website. I tried doing it with getting the amount of objects found in an array then dividing 100 by it, and getting the current one in a for loop and multiplying it by 100/total. Then I would update a text file with the value. Then update the progress bar with that value. However, I want a more efficient way to do it. Also it has to be unique to each user. Thanks.
Share Improve this question asked Sep 2, 2013 at 5:45 UsernameUsername 3731 gold badge4 silver badges13 bronze badges4 Answers
Reset to default 7I found another way to do it, this is to help all of those people that have the same question. I found it out on here http://w3shaman./article/php-progress-bar-script
<?php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Progress Bar</title>
</head>
<body>
<!-- Progress bar holder -->
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
<?php
// Total processes
$total = 10;
// Loop through process
for($i=1; $i<=$total; $i++){
// Calculate the percentation
$percent = intval($i/$total * 100)."%";
// Javascript for updating the progress bar and information
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
// Sleep one second so we can see the delay
sleep(1);
}
// Tell user that the process is pleted
echo '<script language="javascript">document.getElementById("information").innerHTML="Process pleted"</script>';
?>
</body>
</html>
?>
Executing length php process while showing progress, even having multiple progress bars on same page and pre/post hooks: http://pastebin./KSxjC01r
I've done it for myself, because I need it.
Feel free to use it.
If you use PHP for the parsing part then this means that you should somehow get information from that process. This also means that you have to (probably) make ajax requests to another php script which monitors the first one or at least gets some log information from it. I don't think that PHP is the right choice for that. I'll suggest to use nodejs. There, you are able to implement real time socket munication, which is kinda easy.
I've used the solution user3393366 put forth in a post above, and though it outputs an ugly amount of javascript code, it worked real well. I modified it to put out multicolor progress bars based on percentage plete, fixed the multi progress bars on a page issue, added titles to the progress bars, and made optional hide progress bars at pletion functions.. so, no jquery or ajax needed, and works well.. be more than willing to post my mods here.. Sure, maybe not cutting edge stuff.. but gets the job done.