Hi,
I am running a loop that will take a considerable amount of time to execute. At the end of each iteration I am printing a success message to the screen. At present as the loop executes I am left with a white screen and then when it completes I receive all of the success messages in one big hit.
How can I do this so that the success message is printed to the screen in real time, ie each time the loop iterates. I'd like the list to grow as the loop executes.
Is this possible?
Thanks,
Rob.
Loop iteration question
Moderator: General Moderators
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
- SystemWisdom
- Forum Commoner
- Posts: 69
- Joined: Sat Mar 26, 2005 5:54 pm
- Location: A Canadian South of the 49th Parallel
Sounds like you have output buffering on...
You should check out the flush() function, maybe that will help you..
But note (from php.net):
You should check out the flush() function, maybe that will help you..
But note (from php.net):
Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Thanks for the tip! If ound that this piece of code worked just after the text I want to output:
Many thanks,
Rob.
Code: Select all
flush();
ob_flush();
usleep(50000);Rob.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
It seems the above code only worked after I refreshed the page. On the first execute the flush didn't work.
I found this elsewhere and now it works perfectly:
Add this to the first line of the file and it will work.
Rob.
I found this elsewhere and now it works perfectly:
Code: Select all
<?=(str_repeat(' ',256)."n")?>Rob.