Regarding the second question part: Is it "OK" to have "ob_start()" in the beginning of all PHP pages? - it is widely considered to be hack if its purpose is just to prevent the headers already sent error. But then, it's a functional hack. Just beware that reliability depends on wether PHP implicitly flushes (the default buffer size can depend on php.ini settings).
–
marioApr 19 '11 at 12:01

The main advantage of output buffering is that you can use it with the ob_gzhandler which will compress your output so you use less bandwidth. Good to use if your server is not setup to send php files compressed.

Another advantage is if your script uses a database or other constrained resources and you have some output before closing your connections or releasing those resources. Instead of having this kind of thing:

Connect to database

Start sending output to the user

Wait for the user to receive everything

Close the database connection

You have:

Start buffering

Connect to database

Output some things

Close database connection

Send the buffer to the user.

When your script would need to be connected for 100ms to the database and your user need 300 more to download it, you can understand how output buffering can help releasing some stress on the database connections limit.

I know something coded well using a well configured server could nullify those advantages, but you never know who will code after you and you don't always have control of the server it's running on.

-1 - It's not wrong to use ob_start as a method of preventing output being sent. However, normally, it could probably impact performance and mean that you have a layering problem in your code.
–
Mathias Lykkegaard LorenzenJul 9 '13 at 10:50