Configuration caching laravel configuration extends to dozens of files, and including each of them in each request is an expensive process. To merge all your configuration files into one, use:
php artisan config:cache
Keep in mind that any configuration changes will have no effect after you cache them. To update the configuration cache, run the specified command again. If you want to completely get rid of the configuration cache, run
php artisan config:clear
Routing Caching Routing is also an expensive task in Laravel. To cache the rout.php file, run the following command:
php artisan route:cache
Keep in mind that this does not work with closures. If you use closures, this is a great chance to move them to the controller, since the artisan team throws an exception when trying to compile routes that are tied to closures, instead of the correct controller methods. In the same order as the configuration cache, any changes to route.php will no longer have any effect. To update the cache, run the above command every time you make changes to the routes file. To completely get rid of the route cache, run the following command:
php artisan route:clear
Class Map Optimization
Often a medium-sized project extends to hundreds of PHP files. As good coding behavior tells us, everything has its own file. This, of course, is not without its drawbacks. Laravel must include dozens of different files for each request, which is a costly affair.
Therefore, a good optimization method is to declare which files are used for each request (for example, all your service providers, middleware, and some others), and combine them into one file, which will subsequently be downloaded for each request. This is no different than combining all your javascript files into one, so the browser will have to make fewer requests to the server.
Additional compilation files (again: service providers, middleware, etc.) Must be declared by you in config / compile.php, in the key files. After you put everything you need there for every request to your application, merge them into a single file with:
php artisan optimize
Composer startup optimization
This is not only for laravel, but also for any application using the composer.
First, I will explain how PSR-4 autoload works, and then I will show which command you need to execute in order to optimize it. If you are not interested in knowing how the composer works, I recommend switching directly to the console command.
When you ask App\Controllers\AuthController class App\Controllers\AuthController , it first looks for a direct link in the class map. The class map is an array with unambiguous associations of classes and files. Since, of course, you did not add the Login class and the associated file manually to the class map, composer will continue to search the namespaces. Because App is the PSR-4 namespace that comes with Laravel by default and is associated with the app/ folder, composer will try to convert the PSR-4 class name to a file name using basic string manipulation procedures. In the end, he assumes that App\Controllers\AuthController should be in the AuthController.php file, which is in the Controllers/ folder, which, fortunately, should be in the namespace folder, which is app/ .
All this hard work is just to get the class App\Controllers\AuthController in the file app/Controllers/AuthController.php . For the composer to scan the entire application and create direct links of classes and 1-to-1 files, run the following command:
composer dumpautoload -o
Keep in mind that if you have already run php artisan optimize --force, you no longer need to run it. Because the optimize command already tells the composer to create optimized startup.