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

AliN11's avatar

Laravel RAM usage problem

Hello. I'm creating a social network with common features like Facebook and etc, with Laravel. I knew it was risky to use Laravel for large project but i recently decided to calculate my project performance.

I used memory_get_usage() PHP function to calculate amount of allocated memory (RAM). I encountered with a large number: ~8MB !! (with opcache enabled: ~2MB) I tested it even on fresh and pure Laravel and almost got same number !

Old version of this project was running with PHP base. Used RAM on this project was just ~300KB !

And now i'm more worry about launching large project with Laravel.

0 likes
8 replies
Snapey's avatar

worry about it when it becomes an issue... not now.

ohffs's avatar

Laravel will usually use much more memory 'at rest' than a pure php script - so if that's really your only performance concern then you're probably better hand-coding the thing.

Snapey's avatar
Snapey
Best Answer
Level 122

So you build a site that shows a list of users, maybe it allows posts and comments.

But then you realise that you need to do session management better, and then perhaps an ORM would help, oh, and an eventing system... ok, so Ram use is starting to creep up a bit.

Oh, and we want to send emails from our application, and some caching would help, plus its really tedious building out views without any helpers, and some middleware would help filtering and processing of requests, plus some things need to come in via ajax into an API.

Wow, these images on my cheap shared server are really eating up the space, perhaps I ought to create a storage framework that allow images to be pushed off to S3.

It would be nice to have some sort of mechanism that allows notifications to be pushed to users so that they know when their friends have posted....

But hey, I now have a right bunch of spaghetti code and my Ram use is really worryingly high

I wish I had just gone with a polished framework in the first place since now I have all this functionality I'm using a lot more RAM than I expected.

Oh F-it I'll just get a server with 2GB ram since ram is so cheap these days.

5 likes
Cronix's avatar

If you're running a bunch of queries it will eat ram big time. I was processing tens of thousands of records and the memory just kept growing and growing until it killed the server. Laravel does a bunch of crap behind the scenes that it doesn't advertise, and one is query logging. After some research I came across this little gem DB::disableQueryLog();. Now those same queries that eventually killed 128mb ram ran in under 3mb peak memory. I really wish there was somewhere that documented all the unnecessary crap that laravel does under the hood that makes it inefficient so we could just shut it all off. Some of that stuff is nice in dev but would be a killer in production. Yeah you could throw more ram at it too... but I'd rather not have it be such a resource hog to begin with. I like efficiency.

2 likes
bradbforbes's avatar

I'd also make sure you have ran php artisan optimize --force (force if in dev/debug) and composer dumpautoload -o if you're trying to gather data about how your app may run in production.

Frameworks will always use a little more memory than hand-rolled apps, but if you're trying to build a Facebook-like app and don't have a team of dozens or hundreds of developers, then a megabyte of memory isn't what you need to be worrying about right now in my opinion.

1 like
jlrdw's avatar

@bradbforbes you can't use Facebook as a comparison, they have experts who use compiled c++ classes for some stuff. and a compiled c++ class will not consume as much memory. I wish I knew some of that. But you are correct, experts.

I think they are going to start using D

bradbforbes's avatar

@jlrdw, I see your point. I only mentioned Facebook because the author said that he was building something with similar features to Facebook.

Please or to participate in this conversation.