Skip to main content

OptimizationCheck

IfThen....
There's a missing optimization⚠️ Warn

👀 View source on Github

To get the best performance out of your Laravel application, you should optimize.

What does this check do?

This check will raise a warning if any of these are not cached:

  • Routes
  • Config
  • Service providers
  • Packages (auto discovery)
  • Events

How do I fix this?

Luckily, it's very simple. All you need to do is run:

php artisan optimize
php artisan event:cache

Don't forget to make this a part of your deployment script. After each deployment, run the commands again to clear the cache and re-cache things.

Pitfalls of config cache

Before you cache your config, make sure you're not using the env() helper outside of the config folder. As a rule of thumb, you should only ever access your environment variables inside the config folder.

Here's the reason: once you cache your config, Laravel will stop reading your .env file with every request. So the env() helper will start returning null, which can break your application.

👉 Read more about this in the official docs.

Events

Events are not cached when you run the php artisan optimize command. However, the official Laravel docs do suggest you cache your event listeners in production.

In production, it is not efficient for the framework to scan all of your listeners on every request. Therefore, during your deployment process, you should run the event:cache

👉 Read more about event caching