telnetでkeep-aliveの確認

/etc/httpd/conf/httpd.conf


KeepAlive On       ←keep-aliveを有効にする
MaxKeepAliveRequests 100 ←100リクエストまで連続で受け付ける
KeepAliveTimeout 10    ←次のリクエストがくるまで10秒間コネクションを継続する


$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1  ←入力
Host: localhost  ←入力 ※:がないと400 Bad Requestになるので注意
         ←ここでEnter
HTTP/1.1 200 OK
Date: Fri, 29 Nov 2013 12:00:49 GMT
Server: Apache
X-Powered-By: PHP/5.4.14
Content-Length: 19
Content-Type: text/html

(コンテンツが表示されます)

(keep-aliveが有効だとしばらくこのまま待ち状態。続けてリクエスト入力できる)

Connection closed by foreign host. ←KeepAliveTimeoutの秒数が経過すると表示されcloseします。あるいはMaxKeepAliveRequestsの数だけ繰り返しリクエストしても終了します


HTTP/1.0ではkeep-aliveが対応していないので、KeepAlive=Onであっても直ちにcloseする


$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0  ←1.0に変更
         ←ここでEnter ※HTTP/1.0ではHost: は必須ではない
HTTP/1.1 200 OK
Date: Fri, 29 Nov 2013 12:14:47 GMT
Server: Apache
X-Powered-By: PHP/5.4.14
Content-Length: 19
Connection: close
Content-Type: text/html

(コンテンツが表示)

Connection closed by foreign host.