简体   繁体   中英

laravel - Allowed memory size exhausted in queue

I want to fire import from Excel file by queues so I do:
queue file

/**
 * 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));
    });
}

but on listen process I getting standard error Allowed memory size of xxx bytes exhausted . For one moment I tried to set ini_set('memory_limit', '-1'); but still I getting this error. There is full line with this error:
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 .
I'm using: https://github.com/Maatwebsite/Laravel-Excel
Where is can be problem?

Maybe is not a good practice but you can set the memory limit just for the method

/**
* 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));
    });
}

with memory limit = -1, you dont have limit.

I think, you should change maximum upload file size in your php.ini file. So, open your php.ini file and find upload_max_filesize . Then change the value. You should also change post_max_size directive in php.ini file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM