Laravel is a powerful framework with many components and huge code. Its ease of use comes at the expense of performance. Even so, it is still an excellent framework, but In a formal environment, optimization should be done to improve the opening speed of the website.
Recommended:laravel tutorial
1. Turn off debug
Open the .env file and set debug to false.
APP_ENV=local APP_DEBUG=false APP_KEY=base64:sT/aTFeaE13eyao1Raee6jC9Ff+Yle1SE+wtyk0H6B4=
2. Cache routing and configuration
php artisan route:cache php artisan config:cache
3.Laravel optimization command
php artisan optimize
4.composer optimization
sudo composer dump-autoload optimize
5. Use Laravel cache
Use Laravel's Cache method to cache content. There are file cache, database cache, redis cache, and redis can also be used. The predis component can also be combined with multiple caching methods. Using cache in Laravel is so elegant and convenient:
$lists = Cache::remember('travel.destination.lists', 20, function () { return $this->destination->getList(); });
6. Use CDN
My personal website uses Qiniu CDN, which gives you 20G traffic and monthly 20G storage space, I don’t remember the specific amount, but it’s enough for a small website.
7. Use PHP 7 and enable OPcache
This is not just a performance optimization method for Laravel websites, many of them are general website performance optimization methods, of course There are still many places that can be optimized.
Related recommendations, PHP video tutorial learning address://m.sbmmt.com/course/list/29/type/2.html
The above is the detailed content of Tips on optimizing Laravel website performance. For more information, please follow other related articles on the PHP Chinese website!