PHP and jQuery progress bar on parsing

I was wondering how I can create a progress bar to process HTML data. Essentially, the user is looking for something, and I am parsing another site. I tried to do this by getting the number of objects found in the array, then dividing 100 by it, and getting the current in the for loop and multiplying it by 100 / total. Then I would update the text file with the value. Then update the progress bar with this value. However, I want a more efficient way to do this. It must also be unique to each user. Thanks.

+4
source share
4 answers

I found another way to do this to help all those people who have the same question. I found this here http://w3shaman.com/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;\">&nbsp;</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 completed echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>'; ?> </body> </html> ?> 
+6
source

Running the length of the php process when showing progress , even having several progress indicators on the same page and pre / post hooks : http://pastebin.com/KSxjC01r

I did it for myself because I need it.

Feel free to use it.

+3
source

If you use PHP for parsing, it means that you must somehow get the information from this process. It also means that you should (possibly) make ajax requests to another php script that controls the first or at least gets some log information from it. I do not think PHP is the right choice for this. I suggest using nodejs. There you can implement real-time communication, which is quite simple.

0
source

I used the user3393366 solution provided in the post above, and although it outputs an ugly amount of javascript code, it worked very well. I changed it to display multicolor progress indicators based on a percentage, fixed multi-stage bars on the page, added headers to the progress indicators, and made optional hidden progress indicators when completing the completion functions. Thus, no jquery or ajax is needed, and it works well. Be more than willing to post my mods here. Of course, maybe not advanced things .. but it does its job.

-2
source

Source: https://habr.com/ru/post/1500077/


All Articles