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
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!"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.