Hi!
I have set a jobs for save 600 pdf. In a foreach I generate a pdf and I save it in storage. All the procedure works fine but some times I get the error "allowed memory size..."
This is my code:
Job
class ProcessPdf implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $associate;
/**
* Create a new job instance.
*
* @param Associate $associate
*/
public function __construct(Associate $associate)
{
$this->associate = $associate;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$path = storage_path('app/downloads/pdf/' . $this->associate->ragione_sociale . '_' . $this->associate->codice_contribuente . '.pdf');
PDF::loadView('prints.print', ['associate' => $this->associate])->save($path);
}
}
This is the controller:
ini_set('memory_limit', '300M');
foreach($associates as $associate) {
ProcessPdf::dispatch($associate);
}
return redirect('associates')->with('ok_message', 'Il processo di Generazione PDF è iniziato.');
Someone can give me some advise for a best pratic?
Thanks