Welcome Guest, Not a member yet? Register   Sign In
[Solved] Automatic generation of content-length header for CI views?
#1

[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.
(Source)

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.
(Source)

and in Sun's Java Doc
Quote:What makes a connection reusable?

Since TCP by its nature is a stream based protocol, in order to reuse an existing connection, the HTTP protocol has to have a way to indicate the end of the previous response and the beginning of the next one. Thus, it is required that all messages on the connection MUST have a self-defined message length (i.e., one not defined by closure of the connection). 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.
(Source)

I guess in CI it could be done along these lines:
Code:
$length = ob_get_length();
header("Content-Length: $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:
/*
         * Flush the buffer... or buff the flusher?
         *
         * In order to permit views to be nested within
         * other views, we need to flush the content back out whenever
         * we are beyond the first level of output buffering so that
         * it can be seen and included properly by the first included
         * template and any subsequent ones. Oy!
         *
         */    
        if (ob_get_level() > $this->_ci_ob_level + 1)
        {
            ob_end_flush();
        }
        else
        {
            // PHP 4 requires that we use a global
            global $OUT;
            $OUT->append_output(ob_get_contents());
            @ob_end_clean();
        }

br,
Thomas


Messages In This Thread
[Solved] Automatic generation of content-length header for CI views? - by El Forum - 06-10-2009, 11:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB