简体   繁体   中英

Laravel Excel Queue Allowed memory size

I'm trying to export xlsx file that includes around 100,000 rows for 12 months each sheet take one month in laravel 8 using Maatwebsite Excel This process takes around 15~30 mint, So I use a queue in laravel excel in order to keep the job run in the background and notify the user when it finishes. During the process php artisan queue:work --memory=10240 it stops and it shows this error in terminal

在此处输入图片说明

If I run php artisan queue:work the process will stop and the job still in jobs table when I run it again it fail and it shows in failed_jobs table with this error

Illuminate\\Queue\\MaxAttemptsExceededException: Maatwebsite\\Excel\\Jobs\\AppendQueryToSheet has been attempted too many times or run too long. The job may have previously timed out.

What I try to dose and not work with me

1- changing memory_limit post_max_size upload_max_filesize in php.ini I use WAMP SERVER 在此处输入图片说明

2- changing th memory_limit => 6000000 and chunk_size => 1100 in config/excel.php .

Also, I notice all exported files stop at size 555KB在此处输入图片说明

The code to export use queue

class MarkupAccountsYears

<?php

  namespace App\Exports;

  use App\Models\markupPreCalculate;
  use Maatwebsite\Excel\Concerns\FromQuery;
  use Maatwebsite\Excel\Concerns\WithTitle;

  class MarkupAccountsYears implements FromQuery, WithTitle
  {
    

    
    private $month;
    private $year;

    public function __construct(int $year, int $month)
    {
        $this->month = $month;
        $this->year  = $year;
    }


    public function query()
    {   >orderBy('TimeMsc');
       $finalItem = ['real'];
       return markupPreCalculate::query()->select('TimeMsc', '****', 'Login', 'Full_Name', 
        'Group', '****', '****', '****', '****', '****', '****')
         ->whereYear('TimeMsc', $this->year)
         ->whereMonth('TimeMsc', $this->month)
         ->orderBy('TimeMsc')
         ->where(function ($query) use ($finalItem) {
                foreach($finalItem as $keyword){
                  

                          if(is_numeric($keyword))
                          {
                            $query->orwhere('Login', '=',  $keyword);
                          }else
                          {
                            $query->orwhere('Group', 'like',  '%' . $keyword . '%');
                          }
                }
               
            });
    }

      /**
     * @return string
     */
    public function title(): string
    {
        return 'Month ' . $this->month;
    }
}

class MarkupAccount

<?php

namespace App\Exports;

use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\Exportable;

class MarkupAccount implements WithMultipleSheets, ShouldQueue
{
    
    use Exportable;
 
    protected $year;
    
    public function __construct(int $year)
    {
        $this->year = $year;
    }

    /**
     * @return array
     */
    public function sheets(): array
    {
      
        $sheets = [];

       for ($month = 1; $month <= 1; $month++) {
            $sheets[] = new MarkupAccountsYears($this->year, $month);
        }
        
        return $sheets;
    }
}

Class MarkupAccount

<?php

namespace App\Exports;

use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\Exportable;


class MarkupAccount implements WithMultipleSheets, ShouldQueue
{
    
    use Exportable;
 
    protected $year;
    
    public function __construct(int $year)
    {
        $this->year = $year;
    }

    /**
     * @return array
     */
    public function sheets(): array
    {
      
        $sheets = [];

       for ($month = 1; $month <= 1; $month++) {
            $sheets[] = new MarkupAccountsYears($this->year, $month);
        }
        
        return $sheets;
    }
}

Controller

public function downloadExcl(){  
  (new MarkupAccount(2021))->queue('test'.time().'.xlsx')->chain([dump("Done")]);
}

Is there any way to solve this issue or I'm doing something wrong?

我通过增加php folderphp.ini中的memory_limit来解决这个问题,我正在编辑apache folderphp.ini

%wamp%\\bin\\php\\phpx.xx\\php.ini not under %wamp%\\bin\\apache\\apachex.xx\\php.ini

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