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

nategg's avatar

PHP Fatal error: Allowed memory size

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 16384 bytes) in C:\xampp\htdocs\cods\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 331

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 32768 bytes) in C:\xampp\htdocs\cods\vendor\symfony\error-handler\Error\FatalError.php on line 1

Above are the errors I'm getting just trying to connect the server in terminal (php artisan serve) in PHPStorm 2019.3. This is immediately after a reboot, not even a browser window open. xampp control panel is running, server started.

I'm a noob so most of this is over my head.

Problem started a little after I performed "composer require --dev barryvdh/laravel-ide-helper" hoping to clear up some confusing phpstorm warnings/notices. Everything was ok for about a day, then pages wouldn't load, so I stopped the server, tried to start again. Have gotten that error ever since. I just now did "composer remove ... (same) " and it went thru its motions, looks like it removed it all, but I still get the errors when I try to connect to the server. No browser open, not trying to run anything, so not a data problem, right?

I saw some other stackO advice on changing memory size in php.ini, but if I haven't done anything different, and I'm not even running any code, I can't figure why I would need to increase memory. Unless someone here advises different, I wouldn't want to change config files that always worked. Would really appreciate some help.

0 likes
11 replies
Snapey's avatar
Snapey
Best Answer
Level 122

If you are running out of memory like that, it usually points to some sort of recursion.

The main cause of this is having two models both using with to load the other relation.

1 like
nategg's avatar

Wow, Snapey, problem solved! It's like you're watching what I'm doing on my machine, cuz that is what I had just done (adding $with). It didn't occur to me that it could cause any problem, thought I would have to be running the code, loading the pertinent pages for anything like that to have an impact. So Laravel loads models without me even loading a page in a browser? Now I'm wondering which '$with' to remove, which one I won't need later. Too many things to learn. Thanks much. So now, should I reinstall Barry's ide-helper? What does that do for me exactly?

Snapey's avatar

The IDE helper does things like explain Laravel facades to your editor so that it does not highlight it as a problem. It does nothing to your actual code. So, yes, re-install.

You might be loading a model in a service provider?

nategg's avatar

Oh, so maybe this is it in AppServiceProvider?

        View::share('rounds', Round::all());

I can't recall where I got that from, maybe Laracasts, but since rounds are on every page, it seemed like a good thing to do.

Snapey's avatar

possibly, although view composers should only be called when a page is rendered.

nategg's avatar

Hmm. So you would recommend against that View::share?

Snapey's avatar

No, they are good for preparing data for shared components.

You can use with in your models but only ever put it in one of the two halves of a relationship.

nategg's avatar

Ok, got it. Thanks very much.

I see you in discussions all the time. Is there anywhere else to follow you, coding or otherwise?

louk116's avatar

i run same issue on Laravel 8 the cause was in AppServiceProvider in register Method i remove that and it remain working

if ($this->app->environment('local')) { $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class); $this->app->register(TelescopeServiceProvider::class); }

Please or to participate in this conversation.