4

I have a frontend app where i call a PHP script (lets call it script.php) that takes some time to complete. I want to show (on the client side) the percentage completed.

On the file script.php i can at any time calculate the percentage of jobs completed. I searched a bit and a possible solution should be:

  • On the client side call the script.php file
  • Start a polling operation using another php script to get the percentage from script.php
  • Display this percentage on client side.

My problem is how do i get and "share" this percentage value between the script and the other php file to display on the client side.

What options do i have using JQuery/AJAX (i was trying to avoid the use of cached solutions).

Thanks

Barata
  • 2,799
  • 3
  • 22
  • 20
  • better option is to use js/ajax/jquery to trigger the long script call and replace the button with a "loading" image or notice & do something after you get a response, else you would need to fork out the new process before trying to get a response from it, as php is single tread on most setups – Lawrence Cherone Feb 14 '12 at 00:03

1 Answers1

6

All you need on the client side is a javascript function which periodically calls your progress.php script or whatever it's called and get's the latest percent completed. Then you can update the DOM with that value.

Take a look at this thread

jQuery AJAX polling for JSON response, handling based on AJAX result or JSON content

Community
  • 1
  • 1
quickshiftin
  • 66,362
  • 10
  • 68
  • 89
  • I'm having only one problem. Using AJAX i call a poling script (progress.php) that is responsible to get the latest percent completed from script.php. I'm storing in SESSION this value. The problem is that the progress.php waits for script.php to end and only then returns. Do i have to do some kind of multithreading or so? – Barata Feb 14 '12 at 11:41
  • They used to recommed APC for this on just one server, but I think something else has come out that deals w/ multiple uploads across several users simultaneously. I'm not sure if this is it, but it should get you off in the right direction. http://www.ultramegatech.com/2010/10/create-an-upload-progress-bar-with-php-and-jquery/ – quickshiftin Feb 14 '12 at 16:40