Win2003的服务器,IIS,PHP以isapi方式运行,抓包发现,只要访问服务器上的PHP页面,返回完了,其http头部都是 Connection: close
随后http会话就断开了,TCP Close。从而导致服务器高峰期积存的time_wait废连接超多。
于是希望http会话不要立即断开,连接需要保持一段时间。
(根据HTTP 1.1协议,默认情况都应该是保持HTTP连接的,即不会返回 Connection: Close ,或者返回 Connection: Keep-Alive)已确定,每次浏览器递交的GET请求是带着 Keep-alive 标记的。而php页面却无视它,每次都返回 close
而打开同网站的其他页面,如 ASP页面,普通HTML页面等,都不会回带Connection: close已检查IIS管理器上的“保持HTTP连接”是勾上的。请问这是需要如何处理好呢?下面贴出PHP页面和ASP页面的HTTP header抓包对比:-----浏览器请求PHP页面-----
GET /1.php HTTP/1.1
Accept: */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Accept-Encoding: gzip, deflate
Host: www.hypol.com.cn
Connection: Keep-Alive-----服务器返回PHP页面-----
HTTP/1.1 200 OK
Connection: close
Date: Mon, 05 Aug 2013 16:38:36 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-Powered-By: PHP/5.2.17
Content-type: text/html
-----浏览器请求ASP页面-----
GET /1.asp HTTP/1.1
Accept: */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Accept-Encoding: gzip, deflate
Host: www.hypol.com.cn
Connection: Keep-Alive-----服务器返回ASP页面-----
HTTP/1.1 200 OK
Date: Mon, 05 Aug 2013 16:52:10 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 52
Content-Type: text/html
Cache-control: privateIISPHPheaderConnectionclose
随后http会话就断开了,TCP Close。从而导致服务器高峰期积存的time_wait废连接超多。
于是希望http会话不要立即断开,连接需要保持一段时间。
(根据HTTP 1.1协议,默认情况都应该是保持HTTP连接的,即不会返回 Connection: Close ,或者返回 Connection: Keep-Alive)已确定,每次浏览器递交的GET请求是带着 Keep-alive 标记的。而php页面却无视它,每次都返回 close
而打开同网站的其他页面,如 ASP页面,普通HTML页面等,都不会回带Connection: close已检查IIS管理器上的“保持HTTP连接”是勾上的。请问这是需要如何处理好呢?下面贴出PHP页面和ASP页面的HTTP header抓包对比:-----浏览器请求PHP页面-----
GET /1.php HTTP/1.1
Accept: */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Accept-Encoding: gzip, deflate
Host: www.hypol.com.cn
Connection: Keep-Alive-----服务器返回PHP页面-----
HTTP/1.1 200 OK
Connection: close
Date: Mon, 05 Aug 2013 16:38:36 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-Powered-By: PHP/5.2.17
Content-type: text/html
-----浏览器请求ASP页面-----
GET /1.asp HTTP/1.1
Accept: */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Accept-Encoding: gzip, deflate
Host: www.hypol.com.cn
Connection: Keep-Alive-----服务器返回ASP页面-----
HTTP/1.1 200 OK
Date: Mon, 05 Aug 2013 16:52:10 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 52
Content-Type: text/html
Cache-control: privateIISPHPheaderConnectionclose
依次回复你的两点:
1、IIS服务器的keep-alive当然是开启的!请注意看我的提问帖,已经明确指出“已检查IIS管理器上的“保持HTTP连接”是勾上的”。
2、客户端和服务器端 没有其他的“代理服务器”,我就是在本机本地调试的。而且也确定PHP页面获取到的$_SERVER['ALL_HTTP']包含HTTP_CONNECTION:Keep-Alive
ob_start();
$size=ob_get_length();
header(”Content-Length: $size”);
ob_end_flush();
没有长度服务器只有关闭链接了,不然客户端不知道收完响应没有。