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

TheFriendlyHacker's avatar

Allowed Memory Size Exceeded...

I am trying to run some seeders on a local MariaDB database (on a Mac). memory_limit for PHP is set to 256M. When running the seeder, I get this error message:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

I tried commenting out all of the code in my seeder's run method just to see if it would continue throwing the error - it did.

Do you guys have any ideas what might be causing this?

0 likes
6 replies
Cronix's avatar

How many queries are you executing in total? You might try disabling the query logging, which can use a lot of memory especially during processes where tons of queries are being generated.

DB::disableQueryLog();

// run your other queries...
TheFriendlyHacker's avatar

@Cronix The seeder is running 3 writes (creating 3 users with just a name, email and password). I'll disable logging and see if anything changes, but it seems a bit odd either way for just 3 small queries haha.

I have another Laravel project running in the same environment (I believe it's Laravel 5.5), and it's able to seed a lot more data without any issues.

Think it could be a bug in a recent update to 5.6?

Update: Tried disabling query logging with no luck - still getting the same error.

Cronix's avatar

I don't know if it's a bug. I'm not using laravel 5.6 yet. I just know when I was running tens of thousands (yes) of queries in a long running job pulling a lot of data from an api, I could see the memory usage grow and grow on each pass until it exceeded the memory. When I disabled query logging, it consumed no more than 6M in total even after running for hours. Yeah it won't do much, if anything, on just a few queries.

You'd probably need to post your code to be able to figure out what's going on.

TheFriendlyHacker's avatar

There's not a whole lot to see yet haha. And I haven't messed with my user model a whole lot (aka, there wouldn't be anything out of the norm that would cause problems when creating users).

Here we go:

// DatabaseSeeder.php 
public function run()
{
    $this->run(UserSeeder::class);
    $this->run(PolicySeeder::class);
}
// UserSeeder.php
public function run()
{
    DB::disableQueryLog();

  // Admin
  User::create([
    'name' => 'Admin User',
    'email' => '[email protected]',
    'password' => bcrypt('secret')
  ]);

  // Normal User
  User::create([
    'name' => 'Normal User',
    'email' => '[email protected]',
    'password' => bcrypt('secret')
  ]);

  // Denied User
  User::create([
    'name' => 'Denied User',
    'email' => '[email protected]',
    'password' => bcrypt('secret')
  ]);
}

It never makes it past the UserSeeder, even when I comment out all of the code in the "run" method. Tried doing the same for PolicySeeder, same result.

bwrice's avatar
bwrice
Best Answer
Level 11

You've created an infinite loop. I'm guessing your database is loaded with users.

Change

$this->run(UserSeeder::class);

inside DatabaseSeeder.php to

$this->call(UserSeeder::class);

and do the same for PolicySeeder

1 like

Please or to participate in this conversation.