Ways To Optimize The Performance Of A Laravel Application

Published by - Sanjeev Kumar | 27th Dec 2018

Application development with Laravel has always been a pleasurable experience for developers. But just developing and delivering doesn’t complete the job. Your app, once deployed, needs to deliver a seamless experience. For this, developers should underline the problem and focus on improving speed and performance.

In order to achieve the desired results in Laravel development, a developer should follow some key strategies.

Don’t worry, we are for your rescue!

After a detailed analysis and study, we have come up with a list of required strategies and ways to optimize the overall performance of your Laravel application. 

Enhance Artisan Command Uses
Laravel comes with a remarkable and unique tool named Artisan command which is highly beneficial in boosting performance. This is how the common setup goes:

LaravelThis proves to be very useful, especially when the Laravel developer creates several routes and configuration along with a cache as a plain array. This helps in loading cache faster instead of loading the real object.

But don’t forget to re-run this command after you’ve changed config or your routes file. Otherwise, Laravel won’t handle the changes because it has already loaded from cache.

Furthermore, we can cache the user data, settings and locations to limits the number of SQL queries. Make sure you invalidate the cache when the data changes. Also, you need to make sure that you have good indexes for your database, Cache your configs, routes and views. So add these commands to your Forge deploy script.

laravel script

Install/Setup PHP OPcache. OPcache will cache your PHP code and would leave no room for recompiling.

Remove Unused Service
Sometimes it is better to not load all services in your config and to disable unused services inside config file. It is recommended to add a comment to unused service provider in config/app.php. However, make sure that after commenting, you don’t end up breaking the entire functionality of your app.

Minimize Use Of Plugins 
Laravel comes with a whole lot plugins that allow in adding more functionality in the simplest ways. With increased functionality comes more loadable libraries and files, which in turn might slow down the entire process. So make sure to take a look at the providers you are loading through your config/app.php file and cut down unnecessary ones. Moreover, Laravel uses composer to manage its components, so eliminating the unnecessary parts from composer JSON file decreases the dependencies to be loaded.

JIT Compiler
We all know that PHP needs something to interpret the files and execute C routines. As you might guess, this is slow. Every time your server runs a PHP file, it has to convert it to tokens – done by the AST parser and interpret it. It, unfortunately, has to compile it every single time, even though it gets the same result.

Thus, for your application to act fast, you need to compile it once, run it every time method, and fortunately, a JIT compiler does this the best.

The widely used JIT compiler for Laravel is HHVM, created and used extensively by Facebook. It’s also used by Wikipedia, Etsy and thousands of others.


This write-up has shown us various ways and techniques that can be used to optimize the performance of a Laravel application. So it’s time for you to implement these in your applications and witness massive performance improvements. Hope you find this helpful.

Author’s Bio

Sanjeev Kumar - Software Team Lead

Read more posts by

Stay Updated

We regularly share new tech updates, blogs, articles and industry insights. If you enjoy reading them to grow your knowledge! Drop your email address and hit the subscribe button.

Want to hire certifiedLaravel developer for your project?

Let's Talk