Jump to content

Progress of a PHP script


Robbrad

Recommended Posts

I'm sure this has been asked before but I need to know the best way to approach the challenge

 

What I have at present is a site that completes a task where a PHP script goes and performs a load of actions but doesn't inform the user of its progress

 

What I would like is a page that shows the progress of the PHP script to the user and then when complete redirects them to the result.

 

I've had a brief look at jQuery and mootools but I just don't know where to start  :-\

Link to comment
https://forums.phpfreaks.com/topic/185915-progress-of-a-php-script/
Share on other sites

You're going to need to use XHR (or AJAX if you prefer) and polling to make this work.

 

XHR is where you use JavaScript to send requests back to the server "behind the scenes" so that the browser page doesn't reload.  There are many, many tutorials on XHR so I'll leave it up to you to read about it.  My suggestion is make a couple of really simple XHR examples work to just get the feel for what you're doing.

 

As far as your specific question:

1) When the user submits the request, send it via XHR.

2) Start a JavaScript timer and every X seconds send another XHR request to the server to get the status of the original request.

3) The server's response to #2 should tell you in what state the original request is in or if it's finished.

4) Update a portion of the page using HTML DOM to reflect the status gained in #3.

 

#2 and #3 combined are called polling; the JavaScript page is constantly asking the server what's going on with the request:

"Are you done yet?"

"Are you done yet?"

"Are you done yet?"

"Are you done yet?"

"Are you done yet?"

"Are you done yet?"

"Are you done yet?"

"You are? Great!"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.