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

Samer_J's avatar

php artisan optimize?

I'm on Laravel 5.4 and my site struggles to handle 100+ concurrent users on a VPS. Caching is not an option in most cases because my site is mostly dynamic user-generated content.

I've read about php artisan optimize and how it speeds up the site. Is this still true in 5.4? Why is there absolutely no mention of it in any documentation anywhere?

I ran it on my local Vagrant site and this is what it returned:

Generating optimized class loader
The compiled services file has been removed.

Not sure what I should be doing? I can't seem to find any new files.

0 likes
9 replies
Corys8646's avatar

This was deprecated in either 5.4 it 5.5 and removed in 5.6. If your app is in debug mode, I don’t think it will create the compiled file in your /bootstrap/compiled.php without the —force flag

Snapey's avatar

First question, are you running php 7.x ?

Basically optimize is not needed on the later PHP versions, and of course they are already significantly faster

Samer_J's avatar

@Snapey I'm running PHP 7.1.14.

I'm just struggling to understand why my site can't handle more than 100 concurrent users on a VPS. Most pages on my site run a max of 20-30 SQL queries.

Snapey's avatar

Well 20-30 is quite a lot - but you need to work out the average page load time.

100 'concurrent' accesses then I would expect about 10,000 or more logged in at one time

lostdreamer_nl's avatar

start by finding out your real bottleneck. It could be mysql, hard disk, memory etc.

20-30 queries isnt that much by the way IMO, it all depends on what kind of queries and how long they take.

I suggest: Install laravel debugbar : https://github.com/barryvdh/laravel-debugbar This can give you more insight about what queries are running and how much time they take (and how much resources were needed during the request)

Setup mysql slow query log to find any queries that are taking too long, and optimize your queries (use the explain command) and DB for them, correct indexes can make a difference of minutes / request.

Check the hardware, I've been bitten by Azure servers for instance where the hardware for the cloud service had a CPU in country A, it's disk in country B, DB server in country C and it's disk in country D. Testing that mysql server (1000 crud operations) and comparing to a locally installed MySQL server yielded 20x slower responses with the same code and approximate hardware.

Check the server for the amount of allocated memory, and setup MySQL's cache to be about 40-50% of the memory.

Without more info about the code and server it's kinda hard to make good detailed suggestions.

Samer_J's avatar

@Snapey Most of the time my site runs just fine. It's only during 5-10 minute periods during the leagues we run where there are 80-100 people all loading up the site at once, because there are about 30+ teams of 10-15 players all jumping on trying to see who they're playing against in the league. The site's load average jumps up to about 12.0 during this period, but it only lasts for 5-10 minutes.

Samer_J's avatar

@lostdreamer_nl Thank you so much, finally somebody says 20-30 queries isn't that much! I was starting to go crazy, because in some instances it's almost impossible for me to get it under 20 queries due to how complex my site is. And to be honest 7-8 of these queries are fairly simple.

I already have Debugbar installed, it's how I was able to bring my site from 50+ queries down to 20-30. However I've only been looking at the number of queries and now how long each takes, which is what I'll focus on now. I'll have to look into MySQL slow query log, never used it before.

You can find more details about my problem here: https://laracasts.com/discuss/channels/servers/need-some-advice-regarding-laravel-server-usage

However since that post I've brought it down to 20-30 queries and have noticed a small difference in overall performance. Still not enough though.

Snapey's avatar

Focus just as much effort on how much memory is being used for each request. You could be loading too much from the database and trying to manipulate collections in memory rather than optimising the fetched data?

lostdreamer_nl's avatar

@samer_J from what I see in the specs in the other thread: You have 4 GB memory, and are getting in trouble when hitting ~3.5GB in use. I'm guessing most of this is being reserved for MySQL

But the biggest clue is actually the (CPU) load. Your server is going on a load of 5-6 by only 40 users, but you only have 4 cores, so a load of 4 is already CPU @ 100%.

I'm guessing snapey is right, and you are getting back some very big collections and processing them in PHP in an unoptimized way.

Do you have a clue about which pages are the heaviest load ? If not, try to add some debug log info when the request comes in, and when the response goes out, this will give you some valueable info about how long each request takes and how much memory it took to complete.

Answering your question from there: "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?"

No, it is not normal, Any framework will be slower than a comparible bare bones php website because of additional overhead, but it shouldnt be this much difference.

Please or to participate in this conversation.