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

Samer_J's avatar

Need some advice regarding Laravel server usage

So I run an online gaming website which was built using Laravel: https://egn-gaming.com/

I'm currently with Digital Pacific and the plan I'm on is a VPS with 4GB RAM and 4v CPU. I'm running Laravel version 5.4, PHP 7 and the latest version of MariaDB.

The site is relatively fast, however load times increase drastically when multiple users are accessing the site, to a point where you're waiting 5-8 seconds for a page to load.

Most of the content that is being served on the site is dynamic, user generated content that's coming from the database, so naturally there are a bunch of SQL calls being made on every page.

At 40+ concurrent users (via Google Analytics) my server load average jumps up to around 5.0-6.0, while my memory usage hovers between 3.2-3.5GB. At 60-70+ concurrent users it will jump up to around 10.0+ load average and 3.5GB memory, which is when the site begins to hang and become too slow to use. I use htop to get these stats.

I've reduced the amount of SQL queries being made to the database, which has definitely helped (it stopped my site from crashing under heavy load), however it's still not good enough.

I understand that it all depends on the content you're serving, so I'll let you guys know roughly what I'm working with. Using Laravel Debugbar I can see that most pages tend to load in .5 - 1.5 seconds. As for SQL calls, most pages are roughly 30-50 calls, with a few here and there that exceed 50 calls.

I can provide more details if needed.

I now have to upgrade to a managed dedicated server, which will cost me around $300 AUD extra per month. I'm happy to pay for that if it's going to solve my issue, but I'm just wondering if it's normal for me to be upgrading to a dedicated server this early, when I'm barely hitting over 100 consecutive users.

The reason I'm annoyed about this is because I actually used to run an older site, which was a bare bone PHP website that wasn't built with any frameworks: http://www.ausfifa.com

On my old site I could reach 150+ concurrent users and the site wouldn't slow down at all on $30 per month shared hosting.

I've gone from paying $30 a month and being able to handle 150+ concurrent users on a bare bones PHP website to having to fork out $450 a month to be able to handle 100+ users on Laravel. It sounds ridiculous when you think about it like that.

I will be making an effort to optimize the site as much as possible, but if I'm to expect 150+ users to eventually be visiting my site, I just think that any optimizations wont be good enough as long as I'm using Laravel.

My question is, is it normal for Laravel to be using up this many resources? Is a dynamic, database driven Laravel application simply too heavy for a VPS? Or is my site simply not optimized enough?

TL;DR: Is it normal for me to be forking out $450 AUD a month for a dedicated server just for my Laravel application to be able to handle 100+ concurrent users? Or is my site poorly optimized?

0 likes
6 replies
ohffs's avatar

I think ~50 queries per-user-per-page is going to hurt most websites. Is there anything you can do to cache some of that data? Is it using eager loading - missing that on a few queries can have a dramatic effect on query counts. Or is it just all changing all the time? A sticking-plaster solution might be to put something like varnish in front of some routes?

Do you know what's causing the system load to spike? Is it the sql server, php itself, something else? There are some tools you can install like htop and 'iotop' that can help narrow things down

Samer_J's avatar

@ohffs It’s all coming from the SQL server. In my post I mentioned that I used htop.

So 40-60 queries is definitely too much on top of Laravel? On my old site I’d have roughly the same amount of queries per page and didn’t have any issues, but I’m guessing this was fine in raw PHP.

What amount of queries would you think is a normal amount?

click's avatar

I can't answer your question if it normal to upgrade with this amount of users.

Caching

You can try to cache just some query results, some full pages or parts of pages. For example how important is that 'latest videos' on your homepage is real time? If you cache the results for at least 15 minutes that will probably save you some database hits. The same goes for articles, Games overview page, etc. Try figuring out which queries are taking too long.

Too much queries

Maybe you could decrease the amount of queries with some smart 'eager loading'. See for more information https://laravel.com/docs/5.5/eloquent-relationships#eager-loading

Database indexes? / Slow Queries?

Do you know which queries are slow? You could take a closer look at it if needs indexes.

For example if you always sort videos on the created_at datetime column you could try adding an index on that column. You can try to figure out with the mysql EXPLAIN function to see how much work it is to execute your query. More information: https://dev.mysql.com/doc/refman/5.7/en/using-explain.html

Separate database server

You can also try to separate your mysql and app server. It should not be the solution but it could help spreading the load between app and db. But it will also increase your costs because you need to pay 2 servers.. :-)

Use a CDN

Not directly Laravel/Mysql related but when I load the https://egn-gaming.com/games page some of the images and javascript takes me 6 a 7 seconds to load. That is way too much for an image of 42kb. Try using a CDN for your static content (images, css & js). This would also decrease the amount of HTTP requests your app server needs to handle.

Can you see which pages are slow? Or could you maybe dump all the queries of the homepage visit?

1 like
Samer_J's avatar

@m-rk

Thanks for the help. I will try to see what I can cache, but for the most part I do want it to be real time because it's all user-generated content. Is there anyway I can force cache to be updated on a users end? For example when a new video is posted, clear all user video cache?

As for the query count, I've managed to reduce the amount of queries on the busy pages from 40-50 down to 20-30, however the server is still being overloaded.

I will look into the explain function and see if it's certain queries that are slowing the site down. That could be what it is, as I actually did have a query that slowed one of my pages down. I had a query with 3-4 join statements that took about 1-2 seconds to process. Removing the join statements sped it up like crazy.

Maybe I could PM you with more info on the queries being run?

click's avatar

@Samer_J I just saw this: https://laravel-news.com/laravel-model-caching-package talking about https://github.com/GeneaLabs/laravel-model-caching

Maybe this could be a quick caching solution. One important note that would be important in your case:

For best performance a taggable cache provider is recommended (redis, memcached). While this is optional, using a non-taggable cache provider will mean that the entire cache is cleared each time a model is created, saved, updated, or deleted.

tankerkiller125's avatar

@m-rk I have had a couple of small issues with that package, notably the fact that the cache is forever until the element is updated. And if you have a lot of things that never change (user profiles might not change for months) depending on which cache method used it could really eat at RAM or storage space.

Please or to participate in this conversation.