I have a script that can take a while to complete, and to make sure it is actually working (as opposed to getting the server locked up in a loop or something), I would like to regularly flush the output to the user, so the progress and status of the script is visible.

When I first made this script, the [flush() command was enough. Evidently, it’s not enough here - from the description, I guess that the output buffering of the webserver itself is the reason.

Rather than experimenting with the different workarounds (ob_flush() didn’t do anything), I’d like to know if anyone else has had the same problem and what workaround has worked for them…

The sample script is this:

<?php header("Content-type: text/plain"); // to disable html $seconds=10; for ($i=1;$i<=$seconds;$i++) { echo "$i: ".time()."\n"; {flushing code} sleep(1); } For the flushing code to work, this should output one line a second (rather than staying unresponsive for 10 seconds and then showing the entire output).

Good look, I tried just about every flush function without any luck. flush, ob_flush, ob_end_flush, ob_implicit_flush, etc.

Let us know if you find something that works.

Check out Gordaen’s Knowledge, the blog, and the MR2 page.