8

This question already has an answer here:

I want to know the use of compilation in Magento. How it is helpful in my project and its benefit after enabling it.

marked as duplicate by Fabian Schmengler, Siarhey Uchukhlebau, Moose, Jaimin Sutariya, liyakat Jun 16 '17 at 3:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

11

The Compilation feature of Magento will allow you to compile all files of a Magento installation in order to create a single include path to increase performance.

In order to use this tool, the directory includes and the file includes/config.php must both be writable.

Note that before you make any changes to your Magento installation you should always disable compilation. Once the changes are made, run the compilation process and then enable it.

The basic idea behind Magento's compiler feature: Magento’s source is spread out over a large number of modules. For example:

app/code/core/Mage/Core/Model/Abstract.php

app/code/local/Foo/Module/controller/FooController.php

etc ...

It turns out that having PHP search for a large number of include files over a large number of different directories can create a performance bottleneck under certain types of load.

What the compiler does is makes a copy of every class in a Magento system and places them in a single folder. The class’s full name is used for the filename to ensure uniqueness. An example of compiled files:

include/src/Mage_Core_Model_Abstract.php

include/src/Foo_Module_FooController.php

etc...

This is done once. Then, when Magento is configured to use the compiler classes, its autoload will look in the compiler folder instead of running its normal autoload routine. This spares PHP the overhead of transversing the file system for all the different include paths.

I hope it clears your doubt. Please let me know in case of any query or more explanation.

5

What is the Magento Compiler?

Very simply put, the Magento compiler is just a tool that organizes all the .php files within Magento to make things faster. It takes many .php files out of their directories and sticks everything into 1 directory to make searching for files faster.

Magento consists of thousands of .php files for all the different features and functionality. Most of these files are organized and grouped into “Modules” or “Extensions” within the app/code/ directory. These are organized such that most of their files are grouped together in a folder. Let’s take a look at the default Magento module of “Mage_Tax”. The files for this module are located within app/code/core/Mage/Tax/ That folder then contains a few more sub-folders to better organize the module’s contents such as Block/ data/ etc/ Helper/ Model/ and sql/ each with more sub-folders. All in all the app/code/core/Mage/Tax/ folder contains about 289 files nested throughout 58 directories.

How does the Magento Compiler work?

Every time Magento runs it has to quickly move through all those directories and then read and process all the .php files. A standard installation of Magento Community 1.9 has about 5,982 files all scattered throughout 3,149 directories just inside the app/code/ directory. Add a few extensions and this number will continue to grow. You can imagine that it’s not super efficient for the server to have to descend into all those directories to look for the files (especially if your host isn’t running SSDs!). Enter the Magento Compiler.

When you click “Run Compilation” all the compiler does is go through and copy all those thousands of files and stick them all inside the includes/src/ folder with no sub-folders. This makes searching for files much faster. The downside to the compiler is that unfortunately there are many extensions that aren’t written very well that don’t play nice with the compiler. Enabling or running the compiler can cause your site to crash. Luckily if this happens it’s fairly easy to fix with various ways to disable the Magento compiler.

Magento Compiler Pros and Cons.

PROS

1) Extremely easy to use (click “run compilation”)

2) Can speed up your Magento site

3) Actual speed benefits depend on many factors like server hardware, Linux file system tuning, number of extensions, etc.

4) If there are any issues it’s very easy to disable

CONS

1) Can be incompatible with many extensions

2) Sometimes can “crash” your site

3) Usually causes all pages to just be blank white or show the Magento error page if there is an issue)

4) Can be a headache to remember to disable / re-run compilation after installing extensions / making code modifications

5) Can use slightly more disk space due to copying all the module / extension files into the includes/src/ directory.

Source: snapfast

  • Yes it is very helpful me to understand. – Amrit Pal Singh Jun 15 '17 at 13:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.