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

postitief's avatar

Speeding up Laravel

Hello,

At the moment I'm trying to speed up my Laravel website. The site is on my development server blazing fast. But on my production server it is much slower. I contacted my hosting provider and they say it might be slow because it loads a lot of files.

The site is on a clustered hosting and files are stored on a other servers, so they need to be loaded from an internal network. This might cause the site being slower. (The advantage of this cluster hosting is that the resources are actually unlimited. A huge boost in visitors, because the site shows up in for example a TV show, won't take the site down.)

If I look at all the files that are loaded for only showing the homepage, I see that it load over 40 files for swiftmailer. But not a single email will be send from the homepage. So why load 40 of these files..? Probably there are a lot of other files that do not need to be loaded.

Is there a way that Laravel only load files it really needs? I suppose Laravel is already optimized for this. But because it loads 40 swiftmailer on a page that doesn't send e-mails. I wonder if it could be improved.

Edit: There is also the app/compile.php file, is there a default for all files that could be added?

0 likes
7 replies
postitief's avatar

@maxyblack, that's great in 2016, but not for now.

@peitje, that's a nice caching method. But the website is a webshop, prices and stock change continuously. But I might use this caching for other websites.

andy's avatar

My local dev machine is relatively high end with 32gig of ram. My hosting server actually servers up pages faster. That site averages about 12,000 hits a day. I'd say that hosting company even though sounds great there is something that is slowing your code down.

As for caching, I have slowly been adding cache based on function rather than a blanket which means that I need to cache items on edits. I should probably just switch to that package and implement it the same way I'm doing it manually.

Shovels's avatar

Hi @postitief , when you say its slow in production, do you have any details? There are so many elements which could be slowing the page load from back end processing to missing assets, caching disabled, render blocking scripts, etc.

jekinney's avatar

As far as caching you can specify a time amount to cache and/or on any type of change re-cache. So disregarding using cache isn't always good thing.

Secondly on a local environment as your testing things are cached locally on your browser and network lag is almost none. Ping your sever and see your route that it takes, but do it at odd times and a lot. When I lived in Southern California I would trace route a server in Chicago and rarely did I connect as the crow flies. More times then not I would go through Texas and even to Virginia before working my way up to Chicago and every time you connect it has to establish a new route (simplified).

Things to check: css files; should be one. Script files (js) maybe two at the most. Photos need to be as small and minimum as possable. On average a browser only does 4 requests at a time so if more then four of the above items then it has to wait (oddly I.E. 10 does 8 at a time). Secondly check queries. More so with eloquent, it's to easy to have not only 10 plus queries but a huge amount of un needed data as from what I have seen, it's basically select * which isn't appropriate for production. This can be checked with clockwork plugin very easily. I have updated other devs code that had 100 plus queries on certain pages that after fixing did 9 or less.

As you mentioned a lot of php classes and methods being run. Make sure the only run when needed. Eliminate extras where you can (form builder and asset helpers are huge if not used properly, looping through data and outputting Form::input calls a number of php methods each loop and is extremely slow compared to just html).

There's a lot of others but those are the big ones I see. Another thought is if your site has high traffic from a large region think about vertical scaling in different data centers to allow users a closer connection. A slow site will kill your site.

Please or to participate in this conversation.