IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

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

风雪之隅 2011-07-16 20:42:28 累计浏览 4,218 次
本机暂存

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

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

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

比如对于如下脚本:

<?phperror_log("start . " . getmypid(). "\n");sleep(5);error_log("end . " . getmypid() . "\n");

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

start . 3734\nend . 3734\nstart . 3733\nend . 3733\nstart . 3733\nend . 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. translateZ() (2026-06-25 21:18:56)
  2. translateY() (2026-06-25 21:17:56)
  3. translateX() (2026-06-25 21:16:01)

查看更多 前端 文章 →

建议继续学习

  1. 浅析http协议、cookies和session机制、浏览器缓存 (累计阅读 17,446)
  2. 从输入 URL 到页面加载完成的过程中都发生了什么事情? (累计阅读 15,933)
  3. libcurl的使用总结(二) (累计阅读 15,083)
  4. 使用python爬虫抓站的一些技巧总结:进阶篇 (累计阅读 13,301)
  5. HTTP协议Keep-Alive模式详解 (累计阅读 12,103)
  6. 你必须了解的Session的本质 (累计阅读 11,440)
  7. curl 命令使用cookie (累计阅读 10,015)
  8. Hello! 404 (累计阅读 9,384)
  9. 解决 nginx 反向代理网页首尾出现神秘字符的问题 (累计阅读 9,094)
  10. POST与GET的区别及RESTful (累计阅读 7,862)