/Magento-Parallels

Utility ext for parallel data processing in Magento

Primary LanguagePHP

Run heavy pieces of your Magento code in a background process to increase page load speed.

Installation

Just copy files to your magento directory. Make file parallels/out.txt writeable and parallels/run.sh executable.

Usage

For example you have a model class mymodule/model with a method:

function bigCalculations($a, $b) 
{
    $c = $a * $b;
    sleep(30); // Just relax
}

And in some request you wanna run it in a backround. In your module add the following to config.xml

<global>
    <parallels>
        <process>
            <do_my_calculations>
                <model>mymodule/model</model>
                <method>bigCalculations</method>
            </do_my_calculations>
        </process>
    </parallels>
</global>

Then go to your module's class where you want to run these calculations and write:

Mage::getModel('parallels/runner')->run('do_my_calculations', array(2, 3));

run method has 2 arguments:

  1. Process identifier which we mentioned in config.xml
  2. Array with arguments which will be passed to the callback method

So after this bigCalculations execution will be forwarded to the separate process with specified arguments (in our case it will just do 2*3 and sleep). Please note, that in callback method you are free to use any Magento-related stuff like Mage::getModel(...), etc.

Also, parallels/out.txt file will contain output from the last parallel process call. This may help with debugging.