Search code examples
phpajaxprogress-barreal-time

real time progress bar implementation for php


I have two pages. I send ajax call from first page to second page to execute php codes inside it.
execution need long time(1-2 min).how i can create progress bar and show progress percent in first page.
I can calculate progress percent but how show it real time in first page.

firstpage.php

$.ajax({ url: 'secondpage.php',
         data: {'q': data},
         type: 'post',
         success: function(output) {
                    //some code
            }

secondpage.php

    <?php

  // I have some codes here that can calculate progress percent
  // but how to show real time progress percent in firstpage.php

 echo $result;  //final result(for ajax callback)
    ?>

Solution

  • I would use jquery ui progress bar. http://jqueryui.com/progressbar/

    And I would use ajax calls to get the percentage completed and use the completed value to update the progress bar while being on the same page. You could perhaps call the progress every 10 seconds or so, get an update, and update the progress bar accordingly.