Yii2 项目优化小贴士

缓存数据库概要(Schema)

在线上环境中数据库配置文件添加 enableSchemaCache 和 schemaCacheDuration,示例以下:php

'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
        'username' => 'root',
        'password' => 'root',
        'charset' => 'utf8',
        'tablePrefix' => 't_',
        'enableSchemaCache' => true,
        'schemaCacheDuration' => 0,
    ],
    // ...
],

注意:开启这个以后,每次修改数据库结构记得要删除缓存文件!mysql

优化 Composer 自动加载

$ composer dumpautoload -o

禁用调试模式

修改入口文件 web/index.php,禁用调试模式web

defined('YII_DEBUG') or define('YII_DEBUG', false);
相关文章
相关标签/搜索