Rasmus Lerdorf wrote:
Also, just add a single line to your own test script and make it look
like this:
header('Location: http://www.php.net/');
$fp = fopen('/tmp/log.txt', 'w');
for ($i = 0; $i < 30; $i++)
{
$str = "Count $i\n";
echo str_repeat($str, 1000);
fputs($fp, $str);
sleep(1);
flush();
}
Then time how long it takes for the redirect to happen. Is it still
taking 30 seconds?
Yes, it still takes 30 seconds, but each chunk is now 8000 or 9000
bytes. This is with Firefox on Linux (my previous ad hoc tests were on
Mac, because I was traveling). I'd be curious to know what behavior
other people observe with any of these test scripts.
1. Rasmus's original test script:
header('Location: http://www.php.net/');
$fp = fopen('/tmp/log.txt', 'w');
for ($i = 0; $i < 1000000; $i++)
{
$str = "Count $i\n";
echo $str;
fputs($fp, $str);
}
When trying this one, my log.txt shows entries from 0 to 999999, so it
loops the full 1000000 times. I've checked ignore_user_abort(), and it's
false. You can set it in the script to be sure. If the browser aborts
and requests the new URL before the script finishes executing, the log
should reflect this.
2. Chris's original test script:
header('Location: http://www.php.net/');
$fp = fopen('/tmp/log.txt', 'w');
for ($i = 0; $i < 30; $i++)
{
$str = "Count $i\n";
echo $str;
fputs($fp, $str);
sleep(1);
flush();
}
This script takes longer to execute but generates less output. I was
thinking that perhaps browsers are only patient up to a point, but this
is not the case with the browsers I've tried. I get redirected after
about 30 seconds.
3. Chris's modified test script:
header('Location: http://www.php.net/');
$fp = fopen('/tmp/log.txt', 'w');
for ($i = 0; $i < 30; $i++)
{
$str = "Count $i\n";
echo str_repeat($str, 1000);
fputs($fp, $str);
sleep(1);
flush();
}
Rasmus modified the echo in my test script to output 1000 times as much
content. I thought this might work based on section 10.3.3 of RFC 2616
(I referenced this to try to determine why we are observing different
behavior):
"Unless the request method was HEAD, the entity of the response SHOULD
contain a short hypertext note with a hyperlink to the new URI(s)."
A few hundred thousand bytes doesn't seem like a "short hypertext note"
to me, but apparently size doesn't matter. :-)
If anyone can get a browser to redirect (request the new URL) before
receiving the entire 302 response, I'd love to know your test script,
platform, and browser. I have not been able to reproduce this.
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php