2016-06-10 131 views
0

我們有一個網站可以將文件傳輸給我們的客戶。現在,我們開始使用大於300Mb的文件,並且沒有明顯的原因,下載內容隨機失敗。我們收到「下載被中斷」錯誤。文件下載在IIS中隨機失敗PHP

我們登錄到服務器,發現PHP進程有時會在下載開始時關閉,但事件查看器或日誌中沒有任何重要的內容。

下面是提供的下載代碼:

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 Server 2008 R2
  • IIS 7.5
  • PHP 30年5月5日

我的嘗試:

我試圖增加memory_limit的到1024MB,增加超時,增加了腳本的執行時間,我們沒有從提高這些得到任何好處。

從事件查看器,我們得到了很多的錯誤,當下載失敗:

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.這是什麼樣的魔法?

回答

0

顯然,把$fileBuffer12000作品,但不是在11999 ...但是,爲什麼呢?

0

你試過用readfile()替換fread()嗎?它不是打開文件處理程序,而是通過php讀取和傳輸文件塊,它直接將文件內容傳輸到網絡服務器。

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

+0

我試圖做到這一點,但仍然有同樣的錯誤。這讓我想知道它可能是一個IIS配置問題... – CoachNono