flush problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

flush problems

Post by shawngoldw »

Very simply, I can not get flush to work. I'm using this code:

Code: Select all

for ($i=0; $i < 3; $i++) 
{ 
	echo $i;
	flush();
	sleep(1);
}
I've tried with ob_flush() too but can't get that working. I know that the server is set up to allow it because if I run this:

Code: Select all

phpinfo();
for ($i=0; $i < 3; $i++) 
{ 
	echo $i;
	flush();
	sleep(1);
}
phpinfo flushes and then my loop does not. How do I use flush properly?


Thank you,
Shawn
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: flush problems

Post by JakeJ »

shawngoldw wrote: How do I use flush properly?
Sometimes you have to hold the handle down until all the water is gone.

Hey! It's Friday night! What do you want from me? Sanity and clear thinking?
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: flush problems

Post by shawngoldw »

JakeJ wrote:
shawngoldw wrote: How do I use flush properly?
Sometimes you have to hold the handle down until all the water is gone.

Hey! It's Friday night! What do you want from me? Sanity and clear thinking?
haha, too bad I'm stuck in a university town during exams!


It seems that adding

Code: Select all

print str_pad("",5000)."<br>\n";
before flush makes it work....
Whaaa?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: flush problems

Post by McInfo »

Read the description for flush(). One or more of the situations described may apply to you.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: flush problems

Post by shawngoldw »

Thanks, I've read through a lot of that already, thats how I got it to work with the pad. I think it has to do with the output_buffer which is set to 4096 bytes. I'll work it out
Post Reply