Magento2 mode 模式

 

查看当前模式

php bin/magento deploy:mode:show

 

切换模式

magento deploy:mode:set [mode] [-s--skip-compilation]

 

[mode] 不可少,可以是developer 或者 production,默认模式:default
--skip-compilation 是可选的,如果你想在 production 模式的时候跳过 code compilation

 

 

Default Mode

这是一个 fallback 模式,如果没有指定其他模式,就会使用默认模式。

    • 错误被记录到 var/reports 中,但不会展示给用户
    • Static view files are materialized and then cached
      • view files 的变化不会有效直到原来生成的 static view files 被清除了
    • 隐藏自定义的 X-Magento-* HTTP 请求和响应标头
    • 这种模式没有为生产做最好的优化

 

Developer Mode

当你正在开发代码的时候,你应该选择开发者模式,为什么呢?

  • 可以看到错误信息
  • 每次请求都会生成静态文件(static view files)
  • 没有使用缓存
  • 立刻可以看到变化
  • 会在浏览器中显示未捕获的异常
  • 在错误处理程序中抛出异常
  • Exceptions are thrown whenever an event subscriber cannot be invoked(每当事件订阅服务器不能调用时,则将引发异常)
  • 该模式下 var/report 中的系统日志非常详细
  • 显示自定义的 X-Magento-* HTTP 请求和响应标头

该模式会降低性能,所以在生产环境中不该使用它。

 

Production Mode

部署到生产环境中后,你就应该使用生产模式,他是面向客户的,为什么呢?

  • 性能最好
  • 错误会记录到文件系统中,绝对不向客户展示错误。
  • Static view file materialisation is disabled
    • 这意味着 static view file 不会在每次需要时重新生成,他们已经通过 CLI 命令部署到 pub/static 文件夹下
    • 对 view files 的任何更改都要通过 CLI deploy 才会有效果
    • view files 已经被部署到 pub/static ,这个文件夹下只需要 read-only 权限,这样更安全
  • Magento docroot 只有 read-only 权限

developer 模式不应该用在生产环境中。 So, when you need to make changes, you should instead generate static content in development and then use the deployer.php tool to push changes to production\

 

posted @ 2022-10-12 11:05  七彩鱼丸  阅读(109)  评论(0编辑  收藏  举报