无法显示从新服务器下载文件的进度(在以前的服务器上有效)

发布于 2024-11-08 11:02:06 字数 2607 浏览 0 评论 0原文

我一直在开发一个 iPad 应用程序,它使用 ASIHTTPRequest 下载一些 PDF 文件。我一直在使用进度委托为用户显示进度条,显示文件的下载进度。这是 ASIHTTPRequest 设置代码。

request = [ASIHTTPRequest requestWithURL:url];
[request setShouldContinueWhenAppEntersBackground:YES];
[request setDownloadDestinationPath:issue.pdfFilepath];     
[request setDownloadProgressDelegate:vc.progressView];
request.showAccurateProgress = YES;
[request setDelegate:self];
[request startAsynchronous];

从我的开发服务器(“良好的服务器”)读取数据,这一切都运行得非常好。然而,是时候将该应用程序的服务器端移动到我的客户端服务器(“坏服务器”)了。我将所有内容移过来,仍然能够成功下载 PDF,但进度条直到下载完成后才会更新(而不是整个下载过程)。

这是我一直用来输出 PDF 的 PHP:(请注意,我还根据请求的 URL 在数据库中增加查看计数等,因此我不能简单地直接从应用程序访问 PDF。我需要从 PHP 脚本输出 PDF。)

header('Content-type: application/pdf');
header('Content-Disposition:inline filename="downloaded.pdf"');
header('Content-Length: '.remote_filesize($pdfUrl) );
readfile($pdfUrl);

我已经能够确定应用程序没有更新进度栏,因为应用程序最初不知道 PDF 的总大小。我通过在 Safari 中打开这两个文件来确定这一点。

  • 打开“良好服务器”的 URL,状态栏显示“已完成 1.4,共 20.3 MB”。
  • 打开“坏服务器”的 URL,状态栏显示“已完成 1.4 MB ?”。

我已经检查过,我的remote_filesize()函数在两台服务器上返回21331445(大约20 MB)。

因此,我此时的结论是,由于某种原因,“坏服务器”没有正确设置 Content-Length 标头,即使我已经指定了它。 php.ini 文件中是否有任何设置可能会阻止这种情况?任何人都可以提供有关如何进一步解决或排除此问题的任何其他建议吗?

谢谢!

更新 5/18/11

感谢 AJ 在 Firefox 中检查标头的出色建议,我发现“坏服务器”正在使用 gzip 压缩,并且没有设置我的 Conent-Length。比较如下:

好服务器

Server: Apache
X-Powered-By: PHP/5.3.3
Content-Disposition: inline filename="downloaded.pdf"
Content-Length: 21331445
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: application/pdf
200 OK

坏服务器

Server: Apache
X-Powered-By: PHP/5.2.17
Content-Disposition: inline filename="downloaded.pdf"
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=10, max=30
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/pdf
200 OK

我发现一些文章建议通过确保“output_buffering = Off”和“zlib.output_compression = Off”来关闭 gzip php.ini 文件。但情况确实如此,两台服务器上的 phpinfo() 显示 output_buffering 和 output_compression 已关闭。

我们肯定走在正确的轨道上。这里有什么关于为什么要压缩它的建议吗?以及如何预防呢?

谢谢!

最终更新:已解决

我在托管提供商的网站上找到了一个论坛,其中有人解释说 gzip 最近已打开,并详细说明了如何停止它。 http://www.bluehostforum.com/showthread.php?18996-Turning -off-Gzip

基本上,我将以下内容添加到我的 .htaccess 文件中,这会关闭 gzip 压缩。然后,我得到 Content-Length 标头和进度条。

SetEnv no-gzip dont-vary

非常感谢!

I have been developing an iPad application which downloads some PDF files using ASIHTTPRequest. I have been using the progress delegate to display a progress bar for the user showing the file's download progress. Here's the ASIHTTPRequest setup code.

request = [ASIHTTPRequest requestWithURL:url];
[request setShouldContinueWhenAppEntersBackground:YES];
[request setDownloadDestinationPath:issue.pdfFilepath];     
[request setDownloadProgressDelegate:vc.progressView];
request.showAccurateProgress = YES;
[request setDelegate:self];
[request startAsynchronous];

This has all been working wonderfully reading from my development server ("good server"). However, it's time to move the server-side of this application to my client's server ("bad server"). I moved everything over and am still able to download the PDF successfully, but the progress bar does not update until the download is complete (as opposed to throughout the download).

Here's the PHP I have been using to output the PDF: (Please note that I am also incrementing a view-count, etc in my database based on the requested URL, so I cannot simply access the PDF directly from the app. I need to output the PDF from a PHP script.)

header('Content-type: application/pdf');
header('Content-Disposition:inline filename="downloaded.pdf"');
header('Content-Length: '.remote_filesize($pdfUrl) );
readfile($pdfUrl);

I have been able to determine that the app is not updating the progress bar because the app does not know the PDF's total size initially. I have determined this by opening both files in Safari.

  • Opening the URL for the "good server", the status bar shows "completed 1.4 of 20.3 MB".
  • Open the URL for the "bad server", the status bar shows "completed 1.4 MB of ?".

I have checked, and my remote_filesize() function returns 21331445 (approx 20 MB) on both servers.

So, my conclusion at this point is that for some reason, the "bad server" is not correctly setting the Content-Length header even though I have specified it. Is there any setting in the php.ini file which might be preventing this? Can anyone offer any other suggestions of how to resolve or troubleshoot this further?

Thanks!

Update 5/18/11

Thanks to AJ's excellent suggestion of inspecting the headers in Firefox, I found that the "bad server" is using gzip compression, and not setting my Conent-Length. Here's the comparison:

Good Server

Server: Apache
X-Powered-By: PHP/5.3.3
Content-Disposition: inline filename="downloaded.pdf"
Content-Length: 21331445
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: application/pdf
200 OK

Bad Server

Server: Apache
X-Powered-By: PHP/5.2.17
Content-Disposition: inline filename="downloaded.pdf"
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=10, max=30
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/pdf
200 OK

I found some articles suggesting to turn gzip off by making sure that "output_buffering = Off" and "zlib.output_compression = Off" in the php.ini file. This is the case though, and my phpinfo() from both servers shows that output_buffering and output_compression are turned off.

We're certainly on the right track. Any suggestions from here on why this is being gzipped? And how to prevent it?

Thanks!

Final Update: Resolved

I found a forum on the hosting provider's website where someone explained that gzip has recently been turned on, and detailed how to stop it. http://www.bluehostforum.com/showthread.php?18996-Turning-off-Gzip

Basically, I added the following to my .htaccess file, which turns off the gzip compression. Then, I get the Content-Length header, and my progress bar.

SetEnv no-gzip dont-vary

Thanks so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-11-15 11:02:06

只需将结果发布为答案,以便我可以将问题标记为已回答。感谢大家的有用评论!

我在托管提供商的网站上找到了一个论坛,其中有人解释说 gzip 最近已打开,并详细说明了如何停止它。 http://www.bluehostforum.com/showthread.php?18996-Turning -off-Gzip

基本上,我将以下内容添加到我的 .htaccess 文件中,这会关闭 gzip 压缩。然后,我得到 Content-Length 标头和进度条。

SetEnv no-gzip dont-vary

Just posting the result as an answer so I can mark the question as answered. Thanks to all for the helpful comments!

I found a forum on the hosting provider's website where someone explained that gzip has recently been turned on, and detailed how to stop it. http://www.bluehostforum.com/showthread.php?18996-Turning-off-Gzip

Basically, I added the following to my .htaccess file, which turns off the gzip compression. Then, I get the Content-Length header, and my progress bar.

SetEnv no-gzip dont-vary
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文