A note on the above example...
with PHP 4 >= 4.2.0, PHP 5 you can use a combination of ob_get_level() and ob_end_flush() to avoid using the @ (error suppresion) which should probably be a little faaster.
<?php
while (ob_get_level() > 0) {
ob_end_flush();
}
?>