【问题标题】:content-length header from php is overwritten !来自 php 的 content-length 标头被覆盖!
【发布时间】:2011-07-19 14:06:23
【问题描述】:

我试图弄清楚为什么 php 的 Content-Length 标头会被覆盖。 这是demo.php

<?php
header("Content-Length: 21474836470");die;
?>

获取标头的请求

curl -I http://someserver.com/demo.php
HTTP/1.1 200 OK
Date: Tue, 19 Jul 2011 13:44:11 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze3
Content-Length: 2147483647
Cache-Control: must-revalidate
Content-Type: text/html; charset=UTF-8

查看内容长度?它最大为 2147483647 字节,即 2GB。

现在如果像这样修改demo.php

<?php
header("Dummy-header: 21474836470");die;
?>

标题不会被覆盖。

HTTP/1.1 200 OK
Date: Tue, 19 Jul 2011 13:49:11 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze3
Dummy-header: : 21474836470
Cache-Control: must-revalidate
Content-Type: text/html; charset=UTF-8

这是加载的模块

root@pat:/etc/apache2# ls /etc/apache2/mods-enabled/
alias.conf        authz_host.load  dav_fs.load    expires.load  php5.conf    reqtimeout.load  status.conf
alias.load        authz_user.load  dav.load       headers.load  php5.load    rewrite.load     status.load
auth_basic.load       autoindex.conf   dav_lock.load  mime.conf     proxy.conf   setenvif.conf
authn_file.load       autoindex.load   dir.conf       mime.load     proxy_http.load  setenvif.load
authz_default.load    cgi.load         dir.load       negotiation.conf  proxy.load   ssl.conf
authz_groupfile.load  dav_fs.conf      env.load       negotiation.load  reqtimeout.conf  ssl.load

这是一个 phpinfo() :http://pastehtml.com/view/b0z02p8zc.html

Apache 确实支持超过 2GB 的文件,因为我直接访问大文件没有任何问题:

curl -I http://www.someserver.com/somehugefile.zip (5.3 Gig)
HTTP/1.1 200 OK
Date: Tue, 19 Jul 2011 14:00:25 GMT
Server: Apache/2.2.16 (Debian)
Last-Modified: Fri, 15 Jul 2011 08:50:22 GMT
ETag: "301911-1548e4b11-4a817bd63ef80"
Accept-Ranges: bytes
Content-Length: 5713578769
Cache-Control: must-revalidate
Content-Type: application/zip

这是一个 unname -a

Linux pat.someserver.com 2.6.38.2-grsec-xxxx-grs-ipv6-32 #1 SMP Fri Apr 15 17:41:28 UTC 2011 i686 GNU/Linux

希望有人能帮忙!

干杯

【问题讨论】:

  • 它仍然是一个带有 32 位 PHP 的 32 位 Apache - PHP 将你的 bigint 切割成一个有符号的 32 位 int,因此被截断。
  • 只是猜测:PHP 会自动覆盖此标头。可能你使用的是 32 位系统,所以 PHP 无法处理更大的整数。

标签: php apache http-headers large-files content-length


【解决方案1】:

似乎 php 将 Content-length 转换为 int

【讨论】:

    【解决方案2】:

    是的,它肯定是 32 位的东西。好吧,我不想调整 PHP,重新编译什么的,所以暂时我会检查文件大小,如果超过 2GB,我不会发送标头。

    谢谢大家的意见

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多