Home  >  Article  >  Backend Development  >  优化Laravel网站打开速度

优化Laravel网站打开速度

WBOY
WBOYOriginal
2016-06-20 12:26:43749browse

Laravel是一个功能强大的框架,组件很多,代码也很庞大,它的易用方便是牺牲了性能的,即便如此它仍然是一个优秀的框架,但在正式环境下要做好优化提升网站的打开速度。

1.关闭debug

打开.env文件,把debug设置为false.

APP_ENV=localAPP_DEBUG=falseAPP_KEY=base64:sT/aTFeaE13eyao1Raee6jC9Ff+Yle1SE+wtyk0H6B4=

2.缓存路由和配置

php artisan route:cache

php artisan config:cache

3.Laravel优化命令

php artisan optimize

4.composer优化

sudo composer dump-autoload optimize

5.使用Laravel缓存

使用Laravel的Cache方法缓存内容,自带文件缓存,数据库缓存,redis缓存,使用redis也可以用predis组件,也可以多种缓存方式结合。在Laravel中使用就是这么优雅方便:

$lists = Cache::remember('travel.destination.lists', 20, function () {    return $this->destination->getList();});

6.使用CDN

本站用的是七牛CDN,每月送你20G流量和20G存储空间,具体多少不记得了,总之对于小站来说完全足够了。

以上都是本站(tanteng.me)和博客用到的提升网站速度的tips.

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
Previous article:SQL 语句优化Next article:Composer快速入门