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

Domas's avatar
Level 1

Nginx server optimization for laravel

Hello,

Yesterday my system crashed.. I had 1000 concurrent connections in my server. Now, I tried JMeter test with 100 threads (users) and my server average response time was about 5000ms. I think it is extremely slow.. Maybe someone have advices or knows really good articles about servers and laravel optimizations? Or maybe someone have similar problems?

My server: Cores 8 CPU 19.2Ghz RAM 24Gb Disc 240Gb Network 10000Gb

Database is in separate server.

Please share your opinions!

0 likes
3 replies
neilstee's avatar

@domas I had a similar problem and to fix this you need to:

Check your Laravel Application - consider refactoring and optimizing your code, install laravel-debugbar if you haven't already and you will see DB queries that you might not be needed and how fast/slow a page request is. Some common scenarios are, looping MySQL queries (also called n+1, search it), also loops that do some crazy calculations that can be refactored, etc.

Upgrade your server - We have set up a load balancer running 4 instances of the server so we can scale it up when needed. We made sure our routes/config/views is cache, we also use Redis as the cache, session, and queue driver instead of the typical file/database driver which is much slower.

TLDR, just upgrade your server setup or make time to optimize your Laravel application code.

1 like
Tray2's avatar

It's most likely not a problem with nginx but rather the communication between Laravel and the database. So just like @neilstee says install the debugbar to see if you have any n+1 issues. That will hopefully solve some of the problems. The other thing you probably need to do is add the proper indexes to your tables to speed up the quieries.

Just run explain on all your queries that takes time in the debugbar.

I can also recommend the you check out Jonathan Reinink's Eloquent Performance Patterns.

https://eloquent-course.reinink.ca/

Domas's avatar
Level 1

I am running tests on simple laravel blade page, where are no Database Queries at all. I found in my server logs that when I running stress test I get four php-fpm processes which spikes to 100% CPU.

Please or to participate in this conversation.