[Solved] Automatic generation of content-length header for CI views? |
[eluser]ch5i[/eluser]
Hello, I've been researching a caching issue lately (SSL, no-cache & IE) when I came across a nice caching tutorial by mark nottingham. There is one section about writing cache-aware scripts. In the last paragraph he recommends to generate Content-Length response headers: Quote:Generate Content-Length response headers. It’s easy to do, and it will allow the response of your script to be used in a persistent connection. This allows clients to request multiple representations on one TCP/IP connection, instead of setting up a connection for every request. It makes your site seem much faster. Sounds logical enough, but I'm not very familiar with the HTTP and TCP/IP nor with the internal workings of CI, so I can't really judge if this is worth implementing... Any opinions? Wikipedia says Quote:HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using the same TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair. and in Sun's Java Doc Quote:What makes a connection reusable? I guess in CI it could be done along these lines: Code: $length = ob_get_length(); I'm not very familiar with the internal workings of CI, but I guess the right place for something like this would be in the Loader library (Loader.php) somewhere around line 700? Code: /* br, Thomas
[eluser]gtech[/eluser]
CI will create the headers for you, and the content length is already in there for you. If you download firefox, and then download firebug its great for debugging javascript.. but it also shows you what headers are being generated in the net tab. here is a typical header from a controller. Code: Date Wed, 10 Jun 2009 20:29:30 GMT so if my understanding is correct it looks like you do not have to do anything.
[eluser]ch5i[/eluser]
Thanks for your reply, gtech. I use firebug and was looking at the response headers, that's why I started wondering about the content-length header. Here's the response headers from two live sites running CI, both do not send Content-Length (and both have Transfer-Encoding: chunked...?) Code: Date: Thu, 11 Jun 2009 08:18:54 GMT Code: Date: Thu, 11 Jun 2009 08:11:28 GMT From my first post: Quote:Self demarcation is achieved by either setting the Content-Length header, or in the case of chunked transfer encoded entity body, each chunk starts with a size, and the response body ends with a special last chunk. => Does this mean that Content-Length is not needed when transfer-encoding is chunked? I don't think the header is being set in CI, at least I was not able to find it in the core code (other than in download helper, trackback, xmlrpc/s). A configuration issue maybe? br, Thomas
[eluser]gtech[/eluser]
interesting maybee php does it, I will have a look when I get some time.
[eluser]gtech[/eluser]
ah ha this might help [url="http://www.httpwatch.com/httpgallery/chunked/"]http://www.httpwatch.com/httpgallery/chunked/[/url] looks like you do not use content-length when using chunked encoding, as the size of the body is already determined in pre-defined chunk sizes. Infact http1.1 specs suggests you should not use content-length when sending chunked data, and this was a bug in old versions of apache.
[eluser]gtech[/eluser]
it looks like apache determines which headers should be sent, [url="http://bytes.com/groups/php/10395-chunked-encoding-php-apache2"]http://bytes.com/groups/php/10395-chunked-encoding-php-apache2[/url] see Chung Leong's response. As you notice I am using apache2 and it looks like you are using apache, so that might explain the difference in headers.. I am not entirely sure how to configure apache server to use content-length header, its difficult to find searching google. If I find out I will update this reply rather than flooding the bboard.
[eluser]ch5i[/eluser]
Thanks gtech, learned something new today. Quote:http://bytes.com/groups/php/10395-chunke...hp-apache2 see Chung Leong’s response Apache takes care of the correct content length headers (at least for text/html), so there is no point in trying to add them in CI. In my installation the threshold for chunked transfer-encoding seems to lie at 8000bytes of content: 8000 bytes of content: Code: Date: Thu, 11 Jun 2009 17:57:44 GMT 8001 bytes of content: Code: Date: Thu, 11 Jun 2009 17:58:47 GMT br, Thomas
[eluser]gtech[/eluser]
cool glad you got somewhere.. in that link I gave you it mentioned somthing about the php output buffer determing the chunked threshold, in my php5.ini file output_buffering=off... what is it on your installation? does it make any difference?
[eluser]ch5i[/eluser]
I have output_buffering=off as well. Set it to 4096, didn't change anything - maybe there is an option somewhere in httpd.conf? For me that's good enough, as long as it works ![]() |
Welcome Guest, Not a member yet? Register Sign In |