总是在Apache中发送内容长度? [英] Always send Content-Length in Apache?

查看:207
本文介绍了总是在Apache中发送内容长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载了动态由PHP生成一个特别大的JSON字符串。提供一些反馈给用户,我想显示下载进度。

I'm loading a particularly large JSON string that is dynamically generated by PHP. To provide some feedback to the user, I want to show download progress.

我有code想通了,这对静态内容,如图像,JS文件等,但做工精细,它似乎并不为动态文件。

I have the code figured out, and it works fine for static content such as images, JS files, etc. However, it doesn't seem to work for dynamic files.

这是有道理的,因为动态文件没有predictable内容长度,但即使我在PHP补充一点:

This makes sense, since the dynamic files don't have predictable content length, but even if I add this in PHP:

ob_start(function($c) {
    header("Content-Length: ".strlen($c));
    return $c;
});

它仍然不发送头(但如果我添加任何其他的头它工作正常)。

It still does not send the header (but if I add any other header it works fine).

有没有办法强迫阿帕奇发送的Content-Length 头?目前我唯一的选择就是将输出保存到临时文件,并重定向到它,而不是。这会工作,但它是一种混乱的,所以如果可能,我宁愿避免它。

Is there any way to force Apache to send the Content-Length header? Currently my only alternative is to save the output to a temporary file and redirect to it instead. This would work, but it's kind of messy so I'd rather avoid it if possible.

推荐答案

我有类似的问题,但对我来说Content-Length头,因为反应是gzip的COM pressed不是由Apache的发送。当我禁用COM pression的内容长度计算和发送正常。

I had similar problem but in my case Content-Length header wasn't sent by Apache because the response was gzip compressed. When I disable compression the Content-Length was calculated and sent properly.

下面是htaccess的设置来禁用gzip的COM pression的SWF文件只

Below is htaccess setting to disable gzip compression for swf file only

<FilesMatch "\.swf$">
  SetEnv no-gzip 1
</FilesMatch>

这篇关于总是在Apache中发送内容长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆