phpmagentocommand-line

Magento compiler - command line


When I click the compiler status inside the "shell" folder by command line in the root of my store, it returns that the compiler is enabled so as in admin, however when I check that in the root folder of my Magento site is return the status is disabled !

$/var/www/magento# php shell/compiler.php state
Compiler Status:          Disabled
Compilation State:        Compiled
Collected Files Count:    6764
Compiled Scopes Count:    4
$/var/www/magento# cd shell/
$/var/www/magento/shell# php compiler.php state
Compiler Status:          Enabled
Compilation State:        Compiled
Collected Files Count:    6764
Compiled Scopes Count:    4

Although I try to fix this by turning compiler mode off, recompiling, and then turning it back on, I get the same result!


Solution

  • This "works as designed" (except it's just poorly designed). Here's the bit of code from compiler.php that determines status.

    $compilerConfig = '../includes/config.php';
    if (file_exists($compilerConfig)) {
        include $compilerConfig;
    }
    $status = defined('COMPILER_INCLUDE_PATH') ? 'Enabled' : 'Disabl    ed';
    

    the key line is $compilerConfig = '../includes/config.php';. This path goes up one directory from the current directory to find config.php. A PHP shell script's working directory is the one it's invoked from, not the one it lives in. So you you say

    $/var/www/magento# php shell/compiler.php state
    

    the script looks for a file in

    /var/www/magento/../includes/config.php
    

    or

    /var/www/includes/config.php
    

    since it doesn't find one, it assumes a state of disabled.