2017-09-13 75 views
0

耗尽允许内存大小我想火的队列从Excel文件导入,所以我做的:
队列文件laravel - 在队列

/** 
* Execute the job. 
* 
* @return void 
*/ 
public function handle() 
{ 
    Excel::filter('chunk')->load(storage_path('engine-valves.xlsx'))->chunk(500, function($results) { 
     \Illuminate\Support\Facades\File::put(storage_path('data2.txt'), json_encode($results)); 
    }); 
} 

但听过程中,我得到标准错误Allowed memory size of xxx bytes exhausted。有一刻我试图设置ini_set('memory_limit', '-1');,但仍然出现此错误。有这个错误的全部行:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 100663304 bytes) in [app_path]\vendor\phpoffice\phpexcel\Classes\PHPExcel\Cell.php on line 889
我正在使用:https://github.com/Maatwebsite/Laravel-Excel
哪里可以解决问题?

+0

太大的文件保存在内存中,所以你需要阅读它作为一个ByteStream或什么 – aaron0207

回答

0

也许不是一个好做法,但你可以设置内存限制只是方法

/** 
* Execute the job. 
* 
* @return void 
*/ 
public function handle() 
{ 
    ini_set('memory_limit', '-1'); 
    Excel::filter('chunk')->load(storage_path('engine-valves.xlsx'))>chunk(500, function($results) { 
    \Illuminate\Support\Facades\File::put(storage_path('data2.txt'), json_encode($results)); 
    }); 
} 

内存限制= -1,你没有限制。

+0

就像我写的问题 - 我已经设置了这个测试,我仍然得到这个错误,请再读一遍。 –