首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件下载在使用PHP的IIS中随机失败

问文件下载在使用PHP的IIS中随机失败
EN

Stack Overflow用户
提问于 2016-06-10 12:01:38
回答 2查看 291关注 0票数 0

我们有一个网站,将文件传送给我们的客户。现在,我们开始使用大于300 no的文件,而且由于没有明显的原因,下载也在随机失败。我们得到一个“下载被中断”错误。

我们登录到服务器,发现PHP进程有时会在下载开始时关闭,但在事件查看器或日志中都没有显着意义。

,这是交付下载的代码:

代码语言:javascript
复制
public function downloadAction($asset, $csrfToken) {
        if ($this->securityContext->isCsrfProtectionTokenValid($csrfToken) === FALSE) {
            throw new \TYPO3\Flow\Security\Exception\AccessDeniedException();
        }

        // This is a : \TYPO3\Flow\Resource\Resource
        $resource = $asset->getResource();
        $stream = $resource->getStream();

        if (FALSE === $stream) {
            $this->throwStatus(500);
        }

        try {
            $streamMetadata = stream_get_meta_data($stream);
            $modified = filemtime($streamMetadata['uri']);
            $filename = $asset->getResource()->getFilename();

            $this->response->setStatus(200);
            $this->response->setHeader('Content-Type', 'application/octet-stream');
            $this->response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
            $this->response->setHeader('Last-Modified', gmdate('r', $modified));
            $this->response->setHeader('Content-Length', $asset->getResource()->getFileSize());
            $this->response->setHeader('Content-transfer-encoding', 'binary');
            $this->response->sendHeaders();

            @set_time_limit(86400);

            $fileBuffer = 8192;
            while (!feof($stream)) {
                print(fread($stream, $fileBuffer));
                ob_flush();
                flush();
            }
        } finally {
            fclose($stream);
        }

        return '';
    }

,这是我们的设置:

  • Windows 2008 R2
  • IIS 7.5
  • PHP 5.5.30

我尝试了什么:

我试图将memory_limit增加到1024‘t,增加超时,增加脚本执行时间,但我们没有从增加这些时间中获得任何好处。

在事件查看器中,当下载失败时,我们会收到很多错误:

代码语言:javascript
复制
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x0000000000d94b98
Faulting process id: 0x26a0
Faulting application start time: 0x01d1c3157fec8818
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: unknown
Report Id: 9ea4b22a-2f09-11e6-8366-00155d016700

Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: nativerd.dll, version: 7.5.7601.17855, time stamp: 0x4fc85321
Exception code: 0xc0000005
Fault offset: 0x000000000000f4d3
Faulting process id: 0x2170
Faulting application start time: 0x01d1c310490342e2
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: c:\windows\system32\inetsrv\nativerd.dll
Report Id: 9ea48b1a-2f09-11e6-8366-00155d016700

Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: iisfcgi.dll, version: 7.5.7601.17514, time stamp: 0x4ce7c6cb
Exception code: 0xc0000005
Fault offset: 0x0000000000007a47
Faulting process id: 0x28b8
Faulting application start time: 0x01d1c3016d933dec
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\System32\inetsrv\iisfcgi.dll
Report Id: 82a04d74-2f03-11e6-8366-00155d016700

编辑1

它看起来像修改缓冲区,把它放在12000工作,但不是在11999。这是什么巫术?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-13 15:07:51

显然,把$fileBuffer放在12000工厂,而不是在11999.但是为什么呢?

票数 0
EN

Stack Overflow用户

发布于 2016-06-13 09:59:37

您试过用readfile()替换fread()吗?它不打开文件处理程序,通过php读取和传输文件块,而是直接将文件内容流到php服务器。

http://php.net/manual/de/function.readfile.php

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37747776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档