Laravel Tutorials

Speed Up Your Laravel App With Config Caching

Published
Speed Up Your Laravel App With Config Caching image

When deploying your Laravel Application, I’m sure you want to fine tune as much as possible to make it as performant as it can be. The community offers many tools to help you in development like the debugbar and production packages like HTTP/2 Server Push.

Outside of these, Laravel also offers core features to help speed up your application and one of those is configuration caching Artisan command:

php artisan config:cache

This will combine all of the configuration options into one single file which will be loaded quicker by the framework, and this bypasses the env helper for looking up config items through the dotenv package, so you will need to ensure you are not using this anywhere outside of your config files.

Instead of using env you can and should instead use something like the config helper. As an example:

// Change this in your app code:
env('BUGSNAG_API_KEY');
// To something like this:
config('services.bugsnag.key');

Once you run the config:cache command two new files will be generated in app/bootstrap/cache/ folder. These are config.php and services.php and you can look through those to see exactly how it’s compiled down.

Of course, this command is not without some caveats. You should only run this in production because environmental values are designed to change during local development and each developers machine. Secondly, this should be setup so that on deploy the cache is rebuilt, so you are getting new changes each time.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article