Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CLab's avatar
Level 3

Laravel debugbar memory exhaustion due to large SQL query

I have a route which produces a job batch to import large dataset (approx 100,000 entries) chunked in 1000 entries per job. This produces a large SQL query to produce the batch. The issue is that this large SQL query is parsed by debugbar package which maxes out the memory limit in the QueryCollector data collector.

The specific line which causes the error is at C:\...\vendor\barryvdh\laravel-debugbar\src\DataCollector\QueryCollector.php on line 172

 $query = preg_replace($regex, addcslashes($binding, '$'), $query, 1); 

So it seems this preg_replace uses very large amount of memory for very large SQL queries.

I tried to disable to the Debugbar for the route using:

    public function importData() // the route
    {
        \Debugbar::disable();
        $batch = (new ImportDataService())->importDataFromJSON();
        return view('import')->with(['batch' => $batch]);
    }

but it still causes the error.

Any suggestions on how to fix this?

0 likes
2 replies
Snapey's avatar

Add DEBUGBAR_ENABLED=false to your .env

CLab's avatar
CLab
OP
Best Answer
Level 3

@Snapey unfortunately this disables debugbar throughout.

For the moment the workaround I got was to just add the route url to the exceptions after publishing the config using the command:

php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"

Then go to the file config>debugbar.php and add the url to the except key e.g.

    'except' => [
        'telescope*',
        'horizon*',
        '/import/*',   // added to indicate all urls with import will be excluded from the debugbar
    ],

Please or to participate in this conversation.