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

1
  • 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 Commented Feb 14, 2012 at 0:03

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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. ultramegatech.com/2010/10/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.