使用 Apache 和 PHP 对 gzip 进行分块的任何方法
我的网站上有一个 Web 应用程序,需要一段时间(约 10 秒)才能完成页面底部附近的部分内容 - 它已尽可能优化,并且无法选择缓存。
我们通过 .htaccess 指令 SetOutputFilter DEFLATE
在服务器上启用了压缩,问题是这会导致整个页面在开始输出给用户之前被保留直到完成,这在用户看来并不是最佳选择在页面完成之前什么也不做。
我还通过 php ob_start("ob_gzhandler");
方法进行了尝试。
目前,我的 .htaccess 中有一个
限制此特定脚本被压缩。
基本上我的问题是这样的 - 有没有办法说块 gzip 或 deflate 以便用户将其分成几部分,以便他们可以看到页面已经开始加载?
I have a web application on a site that takes a while (~10 seconds) to complete a portion of the page near the bottom - it has been as optimized as it can be, and caching is not an option.
We have compression enabled on the server via an .htaccess directive SetOutputFilter DEFLATE
the problem is this causes the whole page to be held until completion before it starts outputting to the user, this is not optimal as the user sees nothing until the page completes.
I have also tried it via the php ob_start("ob_gzhandler");
method.
Currently I have a <FilesMatch >
in my .htaccess restricting this specific script from being compressed.
Basically my question is this - Is there a way to say chunk gzip or deflate so that the user gets it in pieces, so they can see that the page has begun loading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会说:不。我认为现在有HTTP提供的方式。
I would say: no. I think there is now way provided by HTTP.
如果您使用的是
ob_start("ob_gzhandler")
方法,您可以执行此操作 - 您需要查看 flush 和 ob_flush 函数。一些示例代码 - 尝试使用curl加载,或者使用fiddler检查实际的http响应
不幸的是,浏览器似乎没有以块的形式显示它 - 我认为这是因为每个块的数据太小。您可以通过在测试文件上调用
wget -O - -q http://chunktest/chunktest.php
来验证此效果。这里有一些更有用的资源
If you are using the
ob_start("ob_gzhandler")
method, you can do this - you need to look at the flush and ob_flush functions.Some sample code - try loading with curl, or use fiddler to inspect the actual http responses
Unfortunately, browsers don't seem to display this in chunks - I think this is because the data of each chunk is too small. You can verify this effect by calling
wget -O - -q http://chunktest/chunktest.php
on your test file.There are some more useful resources here
如果页面的加载时间很长,处理该问题的创造性方法是使用非常快速的加载页面,并对页面上加载时间较长的内容进行 ajax 调用。我们为提取详细会员使用统计数据的页面执行此操作...其他网站(例如 Adsense)在其报告页面上执行此操作。
If the page is that long of a load time, the creative way to handle it is to use a very quick loading page with an ajax call to that long-loading content on the page. We do this for the pages that pull detailed member usage statistics... Other sites, like Adsense for example, do this on their reports page.