Magento编译模式 - Magento Compiler Mode
来源:互联网 发布:家用工具品牌 知乎 编辑:程序博客网 时间:2024/06/10 14:44
提高Magento性能的一个很重要的方法是开启Magento的编译模式,可以在后台System>Tools>Compilation,点击Run Compilation Process按钮,一段时间后,我们发现Compiler Status由Disabled变为Enabled,已经编译成功了,打开/includes/src目录,会发现生成了很多文件。
因为在Magento中,我们模块的代码可以放在/app/code/local,/app/code/community,以及/app/code/core这三个目录下,如果Magento需要包含某个文件,系统会依次搜索这三个目录,直到找到这个文件为止,这为我们重写系统的某些文件提供了方便,比如需要修改core目录下的Mage/Catalog/Model/Product.php文件,只需要复制这个文件到local目录下的Mage/Catalog/Model/Product.php,然后修改这个文件即可,这样无需修改核心文件,为我们以后升级系统提供了方便,但由于系统需要在不同的目录中搜索文件,所以效率比较低,使用Compiler功能,系统将把这三个目录下的文件按照优先级顺序复制到/includes/src目录,比如Mage/Catalog/Model/Product.php文件将复制为Mage_Catalog_Model_Product.php,这样系统能够很快的找到需要包含的文件,大幅的提高了效率。
如果我们需要安装新的模块,或者修改已有的模块,我们需要关闭Magento的编译模式,可以在后台System>Tools>Compilation,点击Disable按钮,Compiler Status将由Enabled变为Disabled,添加或修改好模块之后,需要点击Run Compilation Process按钮重新生成编译文件。
此外,Magento提供了一个脚本工具使我们无需进入后台就可以查看和切换编译模式,该脚本位于根目录下的/shell/compiler.php
打开命令行,切换至shell目录:
$cd shell$lsabstract.php compiler.php indexer.php log.php
查看使用compiler.php的方法:
$php -f compiler.php helpUsage: php -f compiler.php -- [options] state Show Compilation State compile Run Compilation Process clear Disable Compiler include path and Remove compiled files enable Enable Compiler include path disable Disable Compiler include path help This help
查看当前的编译状态:
$php -f compiler.php stateCompiler Status: DisabledCompilation State: Not CompiledCollected Files Count: 0Compiled Scopes Count: 0
开始编译:
$php -f compiler.php compileCompilation successfully finished$php -f compiler.php stateCompiler Status: EnabledCompilation State: CompiledCollected Files Count: 6000Compiled Scopes Count: 4
关闭和开启编译:
$php -f compiler.php disableCompiler include path disabled$php -f compiler.php stateCompiler Status: DisabledCompilation State: CompiledCollected Files Count: 6000Compiled Scopes Count: 4$php -f compiler.php enableCompiler include path enabled$php -f compiler.php stateCompiler Status: EnabledCompilation State: CompiledCollected Files Count: 6000Compiled Scopes Count: 4
清除编译:
$php -f compiler.php clearCompilation successfully cleared$php -f compiler.php stateCompiler Status: DisabledCompilation State: Not CompiledCollected Files Count: 0Compiled Scopes Count: 0
我们还可以通过修改/includes/src/config.php文件开启和关闭编译模式,在编译成功后config.php将变为:
define('COMPILER_INCLUDE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'src');
此时只需要注释掉这个语句就可以关闭编译模式:
#define('COMPILER_INCLUDE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'src');
在Mage.php文件中我们可以看到下面一段代码:
Mage::register('original_include_path', get_include_path()); // 保存当前的include_pathif (defined('COMPILER_INCLUDE_PATH')) { // 如果设置为编译模式 $appPath = COMPILER_INCLUDE_PATH; set_include_path($appPath . PS . Mage::registry('original_include_path')); // 添加includes/src为include_path include_once "Mage_Core_functions.php"; include_once "Varien_Autoload.php";} else { // 没有设置为编译模式 $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local'; $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community'; $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core'; $paths[] = BP . DS . 'lib'; $appPath = implode(PS, $paths); set_include_path($appPath . PS . Mage::registry('original_include_path')); // 添加以上四个目录为include_path include_once "Mage/Core/functions.php"; include_once "Varien/Autoload.php";}
我们可以发现,Magento通过检查是否定义COMPILER_INCLUDE_PATH常量来切换编译模式并设置对应模式的文件包含路径
0 0
- Magento编译模式 - Magento Compiler Mode
- Magento编译模式 - Magento Compiler Mode
- Magento编译模式
- Magento 2 模式(mode)设置
- Magento
- magento
- 可以提高Magento速度的插件 - Magento Compiler
- Magento 2 代码编译
- Magento调试模式配置
- 启用 Magento 调试模式
- Magento的观察者模式
- Magento的工厂模式
- magento 开发模式
- How do I disable Magento Compiler?
- How do I disable Magento Compiler?
- Configuring Magento for Development / Debug Mode
- magento -- 打开magento开发的调试模式(开发者模式)
- Magento 2开启开发者模式
- java中的Stack使用
- swift与OC混编(方法调用)
- 【打CF,学算法——二星级】CodeForces 417C Football(构造)
- IMAGE REGISTRATION
- java String字符串转成json数组并且遍历
- Magento编译模式 - Magento Compiler Mode
- iOS9.1 判断定位是否可用 并定位自己位置
- phpMyAdmin 安装
- IOS项目的目录结构和开发流程(转好文)
- 基于Spring MVC的Web应用开发(12) - Form
- Andriod蓝牙开发总结
- Android源码分析—带你认识不一样的AsyncTask(串并行)
- ENVI 5.1破解版安装过程
- Socket send函数和recv函数详解