laravel - 允许的内存大小在队列中耗尽

时间:2017-09-13 11:02:56

标签: php excel laravel

我想通过队列从Excel文件中导入导入,所以我这样做:
队列文件

/**
 * 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
哪里可能有问题?

2 个答案:

答案 0 :(得分: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,你没有限制。

答案 1 :(得分:0)

我认为,您应该在php.ini文件中更改最大上传文件大小。因此,打开您的php.ini文件并找到 upload_max_filesize 。然后更改该值。您还应该在php.ini文件中更改 post_max_size 指令。

相关问题