Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
<?php
ob_end_clean();
header("Connection: close");
ignore_user_abort(); // optional
ob_start();
echo ('Text the user will see');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
// Do processing here
sleep(30);
echo('Text user will never see');
?>
1. I'm thinking that there should be a native PHP function which will close the connection without terminating the script.
2. I don't know enough about how browsers react to headers to be sure that this will work in all browsers.
3. It's not pretty, I prefer one liners.
Actually that doesn't work too well with IE. If there are images that need to be loaded IE will still sit there and wait for the images before it actually draws the page. Nothing you can do from the server side to stop that.