Enable Memcached Support in ZurmoCRM


It’s not easy to install ZurmoCRM and that’s why I encourage to Test your ZurmoCRM with VirtualBox. If you preferred Memcached over Memcache, you may modify ZurmoCRM source code to enable support.

Here is the detail how-to.

Modify Source Code to Enable Memcahed Support

Edit the [where you installed ZurmoCRM]/app/protected/modules/zurmo/components/BeginRequestBehavior.php file and change public function handleApplicationCache($event) as highlighted by bold.

public function handleApplicationCache($event)                                
        {                                                              

            if (MEMCACHE_ON)                                
            {                                                                
                //Yii::import('application.core.components.ZurmoMemCache');            
                $memcacheServiceHelper = new MemcacheServiceHelper();              
            //    if ($memcacheServiceHelper->runCheckAndGetIfSuccessful())        
                {                                                            
                    $cacheComponent = Yii::createComponent(array(          
                        'class'     => 'CMemCache',                        
                        'keyPrefix' => ZURMO_TOKEN,                        
                        'useMemcached'=>true,                                       
                        'servers'   => Yii::app()->params['memcacheServers']));     
                    Yii::app()->setComponent('cache', $cacheComponent);        
                }                                                              
                // todo: Find better way to append this prefix for tests.                 
                // We can't put this code only in BeginRequestTestBehavior, because for API tests we are using
                if (defined('IS_TEST'))                                                                       
                {                                                                                             
                    ZurmoCache::setAdditionalStringForCachePrefix('Test');                                    
                }
            }                                                                                                 
        }

The $memcacheServiceHelper->runCheckAndGetIfSuccessful() calls runCheckAndGetIfSuccessful() in [where you installed ZurmoCRM]/app/protected/modules/install/serviceHelpers/MemcacheServiceHelper.php to check if Memcache has been load.

If you don’t want to skip checking and preferred Memcached, change the following code marked bold in [where you installed ZurmoCRM]/app/protected/modules/install/serviceHelpers/MemcacheServiceHelper.php to force checking for “memcached” instead of “memcache”.

if (extension_loaded('memcached'))

You may use the System Diagnostics in [Administration]→[Developer Tools] to test if it may pass the check for Memcache. I plan to commit extra codes to simplified the use of Memcached in 2014 June.

Load memcached Before First-Time Config ZurmoCRM

Don’t forget to load memcached before use. You may execute or create a shell script to load memcached automatically during startup. Use -m 128 for 1GB and -m 256 for 2GB installed. Then follow Enable Memcahed after Installation to manually enable Memcached.

memcached -u root -l 127.0.0.1 -P 11211 -m 128 -d

Use ps | grep memcached to confirmed it has been loaded into memory.

Now, you may begin to config ZurmoCRM.

Performance Improvement by memcached

On my DS214SE, it takes 34 seconds to display one contact in detail without Memcached and shrinks to 10 seconds if you enable the support.

Reference

  1. ZurmoCRM
  2. Test your ZurmoCRM with VirtualBox
  3. PHP: PHP Manual: Function Reference: Other Services: Memcache
  4. PHP: PHP Manual: Function Reference: Other Services: Memcached
  5. memcached
  6. Oracle: Docs: 15.6.2 Using memcached
  7. Web Developer Juice: 10 baby steps to install Memcached Server and access it with PHP
  8. Zurmo: Forums: Enable Memcache after install
  9. Zurmo: Zurmo Cache System Explained
  10. Synology: DS214SE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s