Question

I'm writing a PHP script that does a lot of repetitive work, and when the client executes it, I'd like it to send back HTML in some way, dynamically, as it completes tasks. (without AJAX?) How can this be done?

Was it helpful?

Solution

You can flush the output buffer, using flush();

So something like:

taskOne();
echo 'Task one finished';
flush();
...

Hope this helps.

OTHER TIPS

Maybe you can use refresh-meta tag, or HTTP header, like this:

header("Refresh: 3; URL=http://www.some.org/some.html");

The browser will then refresh after 3 seconds. If you ask me, this can be kinda anying =) It would be much nicer to inclide an AJAX solution, but it will at least work without too much JavaScript work.

You're better off just polling the server via ajax. Set up a script that can monitor your running tasks and poll that. That way the users's browser isn't always in loading mode, and they can go away from the page and come back if they want.

Then you'd need to refresh the site, since PHP only runs on each page request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top