Simply Boost Laravel Performance In Production

Didik Tri Susanto
Teknomuslim
Published in
2 min readApr 4, 2017
image credit to: https://blog.pisyek.com

When you are going to deploy your Laravel project into production environment, performance becomes matter because real users will use your website or services.

There are many performance optimization methods that can be used as cache optimization, query optimization, server tweaking, etc. But in this case, I will simply using available tools or feature in Laravel itself for better performance.

Disable Unused Service

Sometimes you don’t need to load all services in your config, and you are free to disable unused service inside config file. Just simply add comment to unused service provider in config/app.php. But make sure after commenting, you don’t break whole functionality of your app.

Use Artisan Command

Laravel comes with a great tool named Artisan command and this is very usefull to boost performance using available artisan command. And here is my common setup:

php artisan config:cachephp artisan route:cachephp artisan optimize --force

This is very great especially when you creating a lot of routes and configuration, and you just simply create a cache as plain array, so Laravel become faster to load cache instead loading real object.

But don’t forget to re-run this command after you’ve changed config or your routes file. If not, Laravel will not handle your changes because already loaded from cache.

Composer

Optimize autoload file using composer command:

composer dumpautoload --optimize

or run

composer dumpautoload --classmap-authoritative

Based on composer documentation, option classmap-authoritative:

Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.

Thanks to tfidry for this update.

Optimizing autoload file is also increasing framework performance.

Conclusion

Once again, your Laravel best performance is affected by many factors. If you have done above steps but you feel there is no significant change, you may check other performance tweaking or infrastructure configuration to get better result.

Happy coding, folks!

--

--

Didik Tri Susanto
Teknomuslim

Proud to be Moslem | Introvert | Backend Engineer | Laravel Developer