Current time: 01-22-2021, 04:31 PM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Persistent Connections (keep-alive)
07-18-2010, 03:48 AM (This post was last modified: 07-18-2010 04:39 AM by marvin-miller.)
Post: #9
RE: Use Persistent Connections (keep-alive)
(07-16-2010 04:47 AM)green-watch.org Wrote:  Notice in Request #1 the "Content-Length" value is not there while in Request #2 it is.

I believe that is the key to getting your keep alive working for the main document.

I am just not sure how to do it short of programming.

How do you have the main document being gzipped? Is that programmatic or do you have a setting somewhere?

I think you're on the right track - I found this on the Internet and, while you probably already know it it, I posted it for my own (and future) reference. It's probably going to be handy for other IIS users who encounter this.

Quote:"What's causing IIS to send Connection:Closed in the HTTP headers even though the browser requests Connection:Keep-Alive?

A bit of history will get you to the answer. HTTP isn't a static protocol standard, and new features are added all the time. The original protocol was designed to be stateless, and IIS closed the client's TCP connection at the end of every transmission. Contrary to popular belief, HTTP 1.0 could keep a TCP connection open but in every exchange, both the client and the server had to request that the session stay open. In HTTP 1.1, Keep-Alive connections are the standard, so the connection remains open unless explicitly closed. If you've looked at the packets from HTTP sessions recently, you've probably noticed that the Keep-Alive headers are, in effect, no longer necessary.

For successful Keep-Alive implementation, the client and server must negotiate a way to communicate how much information is being transferred. Internet Engineering Task Force (IETF) Request for Comments (RFC) 2616 (http://www.w3.org/pro tocols/rfc2616/rfc2616-sec8.html #sec8) requires this negotiation for a persistent HTTP session. Section 8.1.2.1 states that

In order to remain persistent, all messages on the connection MUST have a self-defined message length (i.e., one not defined by closure of the connection), as described in section 4.4.

In HTTP 1.1 and HTTP 1.0, this persistent session is achieved through the Content-Length HTTP header. Using the Content-Length header, the server can inform the browser exactly how much information the body of the transmission contains. However, what if you're running a Web application and the server doesn't know exactly how much information it's sending to the client? To permit a Keep-Alive connection in this scenario, HTTP 1.1 included a chunked transfer encoding feature. (For more information about chunked transfer encoding, see Section 3.6 of IETF RFC 2068 at http://www.w3.org/ protocols/rfc2068/ rfc2068.) Using this method, IIS breaks up a transmission into a larger transmission in discreet chunks, each chunk with a unique Content-Length header.

An interesting aspect of chunked encoding is that the client can also use this technique to send information to the server. In IIS 4.0, such a request causes IIS to allocate memory for the expected upload. In fact, if the client sends repeated requests to IIS 4.0 for such a transfer but never sends the information, the requests can effectively shut IIS 4.0 down while the session that's making the requests is alive. For information about this special malformed header attack, see the Microsoft article "Chunked Encoding Request with No Data Causes IIS Memory Leak" (http://support.microsoft.com/support/kb/...6/93.asp). To download the fix for this bug, go to http://download.microsoft.com/download/i...4.2.739.1/ nt4/en-us/chkenc4i.exe. (No Windows NT service packs include this fix.)

So, to answer the question, you know that to support Keep-Alive headers, IIS must send the content length. Thus, you must look at the various methods that IIS can use to deliver content and how those methods relate to using Keep-Alive headers.

IIS can send static content or dynamic content by using Active Server Pages (ASP), Internet Server API (ISAPI), or CGI files. IIS can easily keep a static content session alive because the file length is known and fixed. (it seems to be doing this now with the image files)

A scripting engine such as ASP uses Keep-Alive headers by calculating the length of the content and sending the known content length to the server. The server then uses chunked encoding, if necessary. ASP can use Keep-Alive headers only if you've enabled buffering (the default in IIS 5.0) and you don't flush the buffer. (For more information about ASP and Keep-Alive headers, see the Microsoft article "HTTP Keep-Alive Header Sent Whenever ASP Buffering is Enabled," http://support.microsoft.com/sup port/kb/articles/q238/2/10.asp.)

IIS ISAPI applications can also use Keep-Alive technology, including chunked transfer encoding. (For more information about ISAPI and Keep-Alive headers, see the Microsoft article "Chunked Transfer Encoding," http://msdn.microsoft.com/library/defaul...sref/html/ psdk/asp/devs1pev.asp.) However, you must specifically develop the application to employ these techniques; otherwise, IIS must close the connection after a transfer.

CGI applications in IIS 5.0 and IIS 4.0 can't use the Keep-Alive features of HTTP 1.1, no matter what the applications do. For this reason, you'll see that IIS sends the Connection:Closed HTTP header even though the browser indicates that it wants a Keep-Alive connection and you've enabled Keep-Alive headers in IIS."

from Forcing Keep-Alive Sessions (WindowsIT Pro)

Following up on this article I found this (How to enable chunked transfer encoding with IIS). The important part about it seems to be this;

Send Chunked Data in ISAPI Programming
In Internet Server Application Programming Interface (ISAPI) programming, if you want to send chunked data, add a "Transfer-Encoding: chunked" header, and then send the correctly formatted chunked stream by using InternetWriteFile:

Quote:POST / HTTP/1.1
Host: x.x.x.x:port
Connection: keep-alive
TRANSFER-ENCODING: chunked

Is that why you coughed up this bit of code?;

PHP Code:
$len filesize($filename);
header("Content-Length: $len;\n"); 

After looking through the code for my site it seems that the location where the headers are set globally is here;

PHP Code:
//-------------------------------------------
// print the headers
//-------------------------------------------

    
function do_headers() {
        global 
$ibforums;

        if (
$ibforums->vars['print_headers'])
        {
            @
header("HTTP/1.0 200 OK");
            @
header("HTTP/1.1 200 OK");
            @
header("Content-type: text/html");

            if (
$ibforums->vars['nocache'])
            {
                @
header("Cache-Control: no-cache, must-revalidate, max-age=0");
                @
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                @
header("Pragma: no-cache");
            }
        }
    } 
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Use Persistent Connections (keep-alive) - marvin-miller - 07-18-2010 03:48 AM

Forum Jump:


User(s) browsing this thread: 2 Guest(s)