I have many queue, each queue will export 1 pdf file
Sometimes I get error in laravel log
Allowed memory size of 134217728 bytes exhausted ...
After investigation it seems the cause is memory leak
I tried to reproduce it as follows
Environment
laravel/framework: v10.41.0
barryvdh/laravel-snappy: v1.0.2
h4cc/wkhtmltoimage-amd64: 0.12.4
h4cc/wkhtmltopdf-amd64: 0.12.4
Queue job
<?php
namespace App\Jobs;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class DummyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct()
{
$this->onConnection('database');
}
/**
* Execute the job.
*/
public function handle(): void
{
Log::info('--------------------------------');
Log::info('Start: '.(memory_get_usage() / 1024));
$snappy = SnappyPdf::loadHTML('<div>Something</div>');
// unset($snappy);
// gc_collect_cycles();
}
}
Start memory is continuously increasing until it exceeds the limit
I have many queue, each queue will export 1 pdf file
Sometimes I get error in laravel log
After investigation it seems the cause is memory leak
I tried to reproduce it as follows
Environment
Queue job
Start memory is continuously increasing until it exceeds the limit
I tried unset or gc_collect_cycles, but it didn't fix it laravel-2024-08-19-unset.log laravel-2024-08-19-gc.log