Problem with Flush() and Ob_Flush()

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
Phrank
Forum Newbie
Posts: 6
Joined: Mon Sep 13, 2004 4:55 pm

Problem with Flush() and Ob_Flush()

Post by Phrank »

I have several images to preload for a web page. I wrote a nice routine to show a progress bar and update it after each image is preloaded. Works great on my PC. (XP with IIS). The one thing I have to do is flush the buffer each time I update the progress bar to see the change on the screen.

When I copy this program up to the hosting server, Unix based http://www.fatcow.com, I get an error each time it hits the following command:

<? flush();ob_flush(); ?>

The error is:

Notice: ob_flush(): failed to flush buffer. No buffer to flush. in c:\inetpub\wwwroot\portfolio.php on line 158

If I leave out the ob_flush() and just use flush() I get no error message but it does not refresh the screen and show the progress.

Any help here would be greatly appreaciated.

TIA Frank
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

For Apache Server flush() alone will do.
For IIS, I guess flush() is not working (dont know abt IIS 6 though) but ob_flush() does.
Really don't know how web servers handle these buffer flush methods but ob_flush() forces flushing of buffer and so the server may report an error when flush();ob_flush(); is used together.
If you are uploading to unix, just flush() will do the job.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

The error makes sense. Flushing sends everything in the output buffer, to the client. If you flush() the buffer, that empties it. Calling ob_flush() afterwards also flushes the buffer, and turns on automatic calling of flush() after every output call. The error is just saying there's nothing in the output buffer (since you've just flush()ed it)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ob_ functions are somewhat annoying to get working effectively in IE as ie will not show anything in the browser until a certain amount of information has been sent to it, kinda making the whole point of it somewhat useless.

off-topic i know, but you should be aware of this
Post Reply