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

ccasselman's avatar

Laravel Optimizations or Speed ups?

I am trying to get a brand new Laravel 5 application into production.

I am personally seeing that the framework is actually rather slow to start. Each request whether web page or artisan command or queue listener it takes about .3 - .4 sec for laravel to get booted and running. Which makes it impossible to doing more than 2 or 3 things a sec.

I know many people just prototype things out and it is good enough but I need to squeeze out every bit of performance out of my application.

Has anyone figured out a way to make Laravel faster at any level?

Thanks for your time.

0 likes
66 replies
aarondfrancis's avatar

If queues are your issue, you can run it in --daemon mode and speed it up significantly.

JeroenVanOort's avatar

Are you running Laravel in Homestead without NFS? Disk sync by virtualbox is slow.

1 like
bashy's avatar

Jeez that is slow, what you doing on each load?

MikeHopley's avatar

It might be useful to profile your application and see why you are getting such slow request times. Maybe use something like New Relic?

ShutteR's avatar

Either your server hardware is old, or there is something that's causing a lot of stress when loading your app.

ccasselman's avatar

Hardware is cutting edge.

I have a controller that prints the time and then exits - so its not even a view and I get these results...

Execution Time: 0.4922 s

User time: 1.157186s

System time: 0.343779s

Peak Memory: 11.25 M

Files Included: 266 files

We aren't talking logic here - I am talking the framework. I know that is a taboo subject but I want to know how people are making it scale - if anyone is.

bashy's avatar

One of my installs takes 700ms to load the page with external resources, database, view, css etc...

Sounds like something is wrong with your files or execution of it all.

tjames's avatar

Something is definitely out of whack with your setup if you're getting those type of response times. I have multiple pages in an app I'm currently working on where total response time is under 150ms, and that includes over 20 complex DB queries per page.

bashy's avatar

150ms is local though? Not sure what you based that on if not but for DNS lookup and loading of files, that must be just execution time.

1 like
tjames's avatar

That's total app execution time, which is what OP was referencing in his question.. not over the wire response time.

bashy's avatar

Okay thought so :P I only put the full load time since it's still way below their app boot time...

sitesense's avatar

In my current project, I have a route with a 3 views/partials, 3 db calls and displaying 203 rows in a table.

That's all completed in < 750ms in a VM with debug=true and Barry's debug toolbar with associated resources included.

Are you measuring this correctly?

ccasselman's avatar

Yes, I am measuring correctly because these numbers are coming right out of PHP - I am not making them up.

Are you happy with 750ms for a response - that is what I am getting at? That means you can never do more than 1 thing a sec. I am asking how to get it where it is faster than the current performance of .4s (or 400ms). I have a very successful site ranking in top 300 in the world so I am not new to performance challenges and this performance would crush that site. Just looking for advice.

It appears either there are no optimizations for the framework or everyone is hung up on my measuring technique.

Does anyone have any optimization tips for Laravel to speed up the app boot time since that is required every request?

bashy's avatar

My 700ms was from loading a site fully with no cache in a browser tab. It wasn't PHP execution time. If you want the time from loading the page to getting the main view, it's 80ms (no db cache)

sitesense's avatar

I wouldn't be happy with a response of 750ms on a production site, but as I said, that was in the VM with debugging enabled, no minification, un-cached and running the debug toolbar - which increases response times considerably.

MikeHopley's avatar

It appears either there are no optimizations for the framework or everyone is hung up on my measuring technique.

I think there are optimisations, but people are saying your numbers are way out of line with their experience of running sites on Laravel even without any special optimisations.

ccasselman's avatar

I appreciate all the responses.

So I'd like to know

  1. What are the optimizations

  2. If you think my out of line - any advice on how to debug it? This is my first production system in Laravel so would love some help. The above numbers are as I stated - route->controller->print->hard exit.

Thanks.

bashy's avatar

It's probably a software thing, how are you setting up your web server? How is it dealing with requests?

ccasselman's avatar

What do you mean - it is setup just like my other production servers running my other sites. Fresh install minimal configs.

I am not a server guy - I pay our servers big money to keep the other site running so they keep things running in top conditions.

If you assume the servers are setup in the pristine condition what would you consider next?

bashy's avatar

Okay, so they are people who know how to setup PHP and Apache/Nginx to work together? Have you tested other frameworks? Have you tested it on another server?

ccasselman's avatar

Yes, they know what they are doing - very competent.

I wrote the application in Laravel because I was trying to modernize from codeigniter, but no I haven't tried to rewrite my app in another framework. I wrote it in the latest Laravel, ran into some performance concerns and came here to ask advice.

I have tried other servers with the same performance.

From what others are saying, it appears this performance is normal for Laravel and it is acceptable to most people. If this is as fast as Laravel can run then it is what it is, but I just wanted to know if there was any "Production Performance Tuning Tips" that I didn't know about. It appears there is not anything behond vanilla Laravel out of the box.

bashy's avatar

Well clearly there's something up with your project since it's loading so slow? Mine are fine... and that's without any cache on DB calls.

I just said to try different frameworks (install a fresh framework and just display a page) to see if it's a PHP thing or something you've done in Laravel. Maybe you have something that's making it hang.

graham's avatar

It might be worth you setting up a DigitalOcean server using Forge then signing up for the free trial of New Relic (which you can setup from the Forge dashboard).

If it's still slow on this new server at least New Relic will highlight where/why.

2 likes
tjames's avatar

@ccasselman Something doesn't quite add up here. You say you're trying to push your app to production, but yet also said the figures are from just the framework itself. Except it's not possible to gauge the performance of the framework on anything other than a fresh install, because any code you've added could/would be adding to the overall load/boot time.

From what you've provided so far, it's virtually impossible to give any insight into what could be the cause for the slowness. What packages, if any are you using? Are you using APC or any other type of caching? Have you run artisan optimize? Are you using route caching? Also, how (exactly) are you measuring the load times?

ccasselman's avatar

Sorry for sounding misleading. I meant I setup a straight controller with print inside of my application. Not a fresh install because measuring a fresh install doesn't help my situation.

However, your questions are the first thing that has come close to what I have been looking for. It appears there is route caching option and artisan optimize command. Are there any other performance tips?

tjames's avatar

@ccasselman Without actually seeing the code of your app and what it's actually doing, it's hard to give any specific tips on what might help speed things up. However some general things are:

  1. artisan optimize - this, in some instances can dramatically help with response times, especially if you take the time to add in your commonly used code/classes to the compiler (config/compile.php).

  2. route caching - registering routes can be a significant bottleneck in your app if you have a significant number of them, route caching can help eliminate that bottleneck.

  3. Use caching, and cache everything you can; both in your app and in general. Also make sure you're using the appropriate driver for your use case in config/cache.php (in production apc, memcached or redis are typically preferred).

  4. Remove service providers and packages you aren't using. This also goes for default framework providers as well.

  5. Use deferred service providers when appropriate. While you can't really do much about packages in this aspect, if your own service providers aren't required for every request that hits the app, they should be deferred.

For more fine grained performance tweaks, it will boil down to two different areas, your stack and your code. The stack is easy to tweak and adjust; your codebase, in general, not so much. So if you're building an app where performance will be paramount, you have to be mindful of performance tradeoffs all the time. There's a lot of convenience classes, methods, helpers, etc in Laravel. They are there to make development easier and faster, but overusing them will, without question have a performance impact. Use things like dependency injection sparingly or only when you absolutely need it.

I also suggest using a profiler like Blackfire or New Relic where you can actually visualize the bottlenecks in your app so you can address them appropriately.

11 likes
ccasselman's avatar

@tjames THANK YOU that is the response I have been waiting on.

Re: 5. I've never heard of deferred service providers - can you point me in the right direction?

Next

Please or to participate in this conversation.