NYCPHP Meetup

NYPHP.org

[nycphp-talk] Redirect and ob_flush()

Chris Shiflett shiflett at php.net
Tue Jan 31 10:16:10 EST 2006


Jonathan Hendler wrote:
> Has anyone been able to get around the issue of the HTTP header
> Connection: close being ignored by server/client?

Sending this header is a courtesy. It doesn't dictate whether you can 
close the connection - it just provides a means to notify the other party.

In addition, this header is used to alter the default behavior. In 
HTTP/1.1, keep-alive is the default behavior. In HTTP/1.0, it's not.

> You would use this if you want to execute a redirect and then
> continue with a bunch of other code without the client being
> delayed.

Remember that you're still just sending an HTTP response. If it has a 
3xx status code and a Location header, the client will request the new 
resource, but it can't know about it prior to receiving the original 3xx 
response.

> If you run the code below you will observe a 30 second delay.
> The desired behaviour is that after the the flush(); the client
> moves on.

There are a few things to consider. First, you want to be sure that the 
use of flush() is forcing a chunked response. Use something like 
LiveHTTPHeaders to verify this. (If you see a Content-Length header, 
that's problem number one.)

If you're issuing a chunked response, you want to make sure that the 
client receives the response line and all of the HTTP headers before 30 
seconds have passed. After all, it can't redirect before it is asked to.

Lastly, you want to be sure that other systems aren't buffering this 
response and interfering with your plan. If you're using mod_gzip, 
Apache is likely buffering the response, waiting the full 30 seconds 
before sending it to the client (compressed). Internet Explorer buffers, 
so that it doesn't begin to render until it has received a significant 
portion of the response (making its rendering appear faster, although 
the overall delivery is actually slower).

It's not required that a client abort a transaction as soon as it knows 
it must request another resource, but these are the major 
characteristics you want to check to make that scenario possible.

Hope that helps.

Chris

-- 
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/



More information about the talk mailing list