Home > PHP Framework > Laravel > body text

Tips on optimizing Laravel website performance

藏色散人
Release: 2020-03-14 13:54:41
forward
2784 people have browsed it

Tips on optimizing Laravel website performance

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=
Copy after login

2. Cache routing and configuration

php artisan route:cache
php artisan config:cache
Copy after login

3.Laravel optimization command

php artisan optimize
Copy after login

4.composer optimization

sudo composer dump-autoload optimize
Copy after login

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();
});
Copy after login

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: https://www.php.cn/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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template