Home  >  Article  >  PHP Framework  >  Laravel website performance optimization tips

Laravel website performance optimization tips

不言
不言Original
2018-07-31 17:09:072990browse

The function of the Laravel framework is very powerful, and there are many things in it. Even so, it is still an excellent framework, but in a formal environment it must be optimized to improve the opening speed of the website. Therefore, the following article is for Everyone shared several tips for Laravel website performance optimization.

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, including file cache, database cache, and redis cache. You can also use predis components when using redis, or you can combine 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

This site uses Qiniu CDN, which gives you 20G traffic and 20G monthly I don’t remember the exact amount of storage space, but it’s enough for a small website. This is my Qiniu Cloud invitation link: https://portal.qiniu.com/signup?code=3l7l12rccmc0i

7. Use PHP 7 and enable OPcache

Use PHP 7 and turn on OPcache

This is not just a performance optimization method for Laravel websites, many of them are general website performance optimization methods, and of course there are many places that can be optimized.

The above are the techniques used by laravel websites to improve website speed. For more laravel content, please pay attention to the laravel framework introductory tutorial.

Recommended related articles:

In-depth analysis of controllers in the Laravel framework

Commonly used auxiliary functions in the Laravel framework Introduction

Related course recommendations:

The latest five Laravel video tutorial recommendations in 2017

The above is the detailed content of Laravel website performance optimization tips. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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