php - Download from Laravel storage without loading whole file in memory -


i using laravel storage , want serve users (larger memory limit) files. code inspired post in , goes this:

$fs = storage::getdriver(); $stream = $fs->readstream($file->path);  return response()->stream(     function() use($stream) {         fpassthru($stream);     },      200,     [         'content-type' => $file->mime,         'content-disposition' => 'attachment; filename="'.$file->original_name.'"',     ]); 

unfourtunately, run error large files:

[2016-04-21 13:37:13] production.error: exception 'symfony\component\debug\exception\fatalerrorexception' message 'allowed memory size of 134217728 bytes exhausted (tried allocate 201740288 bytes)' in /path/app/http/controllers/filecontroller.php:131 stack trace: #0 /path/vendor/laravel/framework/src/illuminate/foundation/bootstrap/handleexceptions.php(133): symfony\component\debug\exception\fatalerrorexception->__construct() #1 /path/vendor/laravel/framework/src/illuminate/foundation/bootstrap/handleexceptions.php(118): illuminate\foundation\bootstrap\handleexceptions->fatalexceptionfromerror() #2 /path/vendor/laravel/framework/src/illuminate/foundation/bootstrap/handleexceptions.php(0): illuminate\foundation\bootstrap\handleexceptions->handleshutdown() #3 /path/app/http/controllers/filecontroller.php(131): fpassthru() #4 /path/vendor/symfony/http-foundation/streamedresponse.php(95): app\http\controllers\filecontroller->app\http\controllers\{closure}() #5 /path/vendor/symfony/http-foundation/streamedresponse.php(95): call_user_func:{/path/vendor/symfony/http-foundation/streamedresponse.php:95}() #6 /path/vendor/symfony/http-foundation/response.php(370): symfony\component\httpfoundation\streamedresponse->sendcontent() #7 /path/public/index.php(56): symfony\component\httpfoundation\response->send() #8 /path/public/index.php(0): {main}() #9 {main}   

it seems tries load of file memory. expecting usage of stream , passthru not this... there missing in code? have somehow specify chunk size or what?

the versions using laravel 5.1 , php 5.6.

it seems output buffering still building lot in memory.

try disabling ob before doing fpassthru:

function() use($stream) {     while(ob_end_flush());     fpassthru($stream); }, 

it there multiple output buffers active why while needed.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -