Notice that ob_end_clean() does discard headers.
If you would like to clear the output buffer, but not the headers (because you use firephp for example...), than this is the solution:
<?php
...
$headers = array();
if ( !headers_sent() ) {
$headers = apache_response_headers();
}
ob_end_clean();
ob_start();
if ( !empty( $headers ) ) {
foreach ( $headers as $name => $value ) {
header( "$name: $value" );
}
}
...
?>
I use it in a general exception handler in a web application, where I clear the buffer (but not the debug-info-containing headers), and send a 500 error page with readfile().
Good PHPing,
Tamas.