Page 1 of 1
Terminate http stream.
Posted: Sun Jun 17, 2007 11:32 pm
by Benjamin
I have been digging through the manual looking for a way to force a browser to stop waiting for data. See the following code..
Code: Select all
echo 'Hello Browser';
// insert command to tell browser no more data is coming..
// do some other stuff
sleep(10);
As it is, the page won't load for 10 seconds. What possible solutions are there to this issue?
Posted: Sun Jun 17, 2007 11:44 pm
by Benjamin
Spoke too soon.. Found this in the manual..
Code: Select all
<?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');
?>
Chapter 40. Connection handling
Looks like a pretty crappy way to do it though. Anyone have anything better?
Posted: Mon Jun 18, 2007 1:21 am
by Weirdan
Looks like a pretty crappy way to do it though.
What's wrong with that?
Posted: Mon Jun 18, 2007 1:34 am
by Benjamin
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.
Posted: Mon Jun 18, 2007 2:55 am
by AKA Panama Jack
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.