技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> 发现 --> 浏览器多tab打开同一URL串行化的问题

浏览器多tab打开同一URL串行化的问题

浏览:2800次  出处信息

最近同事”神经病”同学的项目中, 发现一个问题.

用firefox打开多个tab, 每个tab都去请求同一个URL(尽量同时), 会发现, 这些请求, 会被浏览器串行化.

也就是说, 浏览器会在第一个页面请求结束以后, 再发起第二个请求,

比如对于如下脚本:

  1. <?php
  2. error_log("start . " . getmypid(). "\n");
  3. sleep(5);
  4. error_log("end . " . getmypid() . "\n");

用firefox打开多个tab同时请求这个脚本, 观察error_log

  1. start . 3734\n
  2. end . 3734\n
  3. start . 3733\n
  4. end . 3733\n
  5. start . 3733\n
  6. end . 3733\

多方求证这个问题, 但无果, 得到的都是对这个现象的描述, 但没有得到为什么浏览器会这么做, 或者是什么让它们这么设计, 后来得到在mod_perl中的一段叙说:

Certain browsers will serialize requests to the same URL if accessed from different windows. For example if you have a CGI script that does:

for (1..100) {
print “$$: $_\n”;
warn “$$: $_\n”;
sleep 1;
}
And two concurrent requests are issued from different windows of the same browser (for those browsers that have this bug/feature), the browser will actually issue only one request and won’t run the second request till the first one is finished. The debug printing to the error_log file helps to understand the serialization issue.

Solution? Find a UA that doesn’t have this feature, especially if a command line UA will do (LWP comes to mind). As of this writing, opera 6, mozilla 1.0 on linux have this problem, whereas konqueror 3 and lynx don’t.

随后, 我验证了chrome也有这个问题, 不过上面的文字也说了, 这些是特定浏览器的特定行为, 比如命令行的wget, ab之类的就没有这个特定行为.

我也尝试翻看HTTP 1.1RFC和webkit的源代码, 不过也无奈找不到线索…

bitbull说可能是为了复用一个链接, 不过此时通过netstat, 会发现本地确实是打开了多个链接, 所以应该不是为了复用一个链接而这么设置的.

各位如果有对这个特性详细描述, 并且解释为什么这么设计的文档, 请一定转发一个给我.

thanks

建议继续学习:

  1. 浏览器的工作原理:新式网络浏览器幕后揭秘    (阅读:19211)
  2. 浅析http协议、cookies和session机制、浏览器缓存    (阅读:15469)
  3. 从输入 URL 到页面加载完成的过程中都发生了什么事情?    (阅读:14218)
  4. 程序员眼里IE浏览器是什么样的    (阅读:6596)
  5. 浏览器的渲染原理简介    (阅读:6131)
  6. 各种浏览器审查、监听http头工具介绍    (阅读:6011)
  7. 图说浏览器战争:火狐、微软、谷歌那些事    (阅读:5825)
  8. 浏览器缓存机制    (阅读:5614)
  9. [译]Google Chrome中的高性能网络    (阅读:4848)
  10. 12款很棒的浏览器兼容性测试工具推荐    (阅读:4692)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1