Ajax/PHP - should I use one long running script or polling?

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-06-02T18:34:14Z Indexed on 2010/06/02 19:04 UTC
Read the original article Hit count: 272

Filed under:
|
|
|
|

Hello,

I have a PHP script that is kicked off via ajax. This PHP script uses exec() to run a separate PHP script via the shell.

The script that is called via exec() may take 30 seconds or so to complete. I need to update the UI once it is finished.

Which of these options is preferred?

a) Leave the HTTP connection open for the 30 seconds and wait for it to finish.
b) Have exec() run the PHP script in the background and then use ajax polling to check for completion (every 5 seconds or so).
c) Something else that I haven't thought of.

Thank you, Brian

© Stack Overflow or respective owner

Related posts about php

Related posts about AJAX