服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > magento教程 >

magento2每种模式的特点及如何切换

时间:2017-03-12 00:47来源:未知 作者:最模板 点击:
在开始 Magento 2 使用之前,需要了解一些基本的东西,其中之一就是系统可用的模式。 每种模式的主要特点 如何切换模式 如何显示当前的模式 Magento 2 总共有三种主要模式:developer(开

在开始 Magento 2 使用之前,需要了解一些基本的东西,其中之一就是系统可用的模式。

  • 每种模式的主要特点
  • 如何切换模式
  • 如何显示当前的模式 
    Magento 2 总共有三种主要模式:developer(开发者模式), production(生产模式), default(默认模式)

还有一个 maintenance (维护)模式,该模式运行方式很特别,他将完全阻止对系统的访问。

magento2每种模式的特点及如何切换

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

可以看到错误信息 
每次请求都会生成静态文件(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

Default Mode

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

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

这是 Magento 2 预置的一个功能。当你在给系统升级或做其他改变的时候,你不想让用户使用网站,这时候会返回给用户 503 提示。

Bootstrap::assertMaintenance() 方法控制该模式,你可以通过创建一个标识文件(var/.maintenance.flag)来启用该模式。

You can specify a group of people to have access to the site while this mode is employed by placing the associated IPs in var/.maintenance.ip.

如何切换模式

CLI 命令

magento deploy:mode:set [mode] [-s|–skip-compilation] 
[mode] 不可少,可以是developer 或者 production 
–skip-compilation 是可选的,如果你想在 production 模式的时候跳过 code compilation

Web Server Environment

(这种方式博主没有试过,暂时不翻译,以后试验过理解了再补上) 
Apache web servers with mod_php support this method. The environment variables can be set in the main apache configuration or in the .htaccess.

If you are using an Apache system you can do the following:

Open Apache 
Open the .htaccess file 
Use the MAGE_MODE system environment variable to specify the mode as follows: 
SetEnv MAGE_MODE [mode] 
[mode] is required; it can be either default, developer or production

After setting the mode you will need to restart the web server for it to take effect.

php-fpm Environment

You can specify the mode in the php-fpm config or in the system environment in which the php-fpm is started.

In the php-fpm config file, the value can be set as follows:

env[MAGE_MODE]=[mode] 
[mode] is required; it can be either default, developer or production

显示当前模式

CLI 命令:

magento deploy:mode:show 
然后你会看到如下信息:

Current application mode: [mode].

(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(1)
100%
------分隔线----------------------------