How to Configure Magento to use memcached

Reading Time: 2 minutes

Magento runs more data and objects from its database when a customer visits and buys something from the store. These objects are defined in the Magento core, in PHP calls and in different page blocks and these can reduce the performance of your Magento store.

If you want to optimize the speed of your Magento ecommerce store, one of the recommended solutions is to configure and use the Magento Memcached support.

What is Memcached?

Memcached is a distributed memory cache that accelerates large-scale web applications with dynamic databases. It reduces the load of database requests on a server and displays data through the cache whenever an external data source requests it.

Configure Magento to use memcached

To configure your Magento with MemCached, open <your Magento install dir> /app/etc/env.php in a text editor

Identify the following:

'session' =>

    array (

    'save' => 'files',

),

Change it to this:

'session' =>

    array (

      'save' => 'memcached',

      'save_path' => '<memcache ip or host>:<memcache port>'

),

Memcached has optional startup parameters that are beyond the scope of this guide. You can find more information about them in the memcached documentation , source code, and change logs.

Verify that Memcached works with Magento

To verify that memcached works with Magento:

    1. Delete the contents of the following directories in the Magento installation directory: rm -rf var / cache / * var / page_cache / * var / session / *
    2. Go to any showcase page.
    3. Log in to Magento admin and go to different pages.If no errors appear, congratulations! memcached works! Optionally, you can review memcached storage as discussed in the next step.If errors are displayed (such as an HTTP 500 (internal server error)), enable developer mode and diagnose the problem. Make sure memcached is running, configured correctly, and that env.php has no syntax errors
    4. (Optional) Use Telnet to examine memcached storage.

The results are displayed similar to the following:

“STAT elements of the terminal: 3: number 1 elements STAT: 3: age 7714 elements STAT: 3: evicted 0 elements STAT: 3: evicted_nonzero 0 STAT elements: 3: evicted_time 0 STAT elements: 3: outofmemory 0 STAT elements: 3: tailrepairs 0

Andrea SaccĂ 
FOUNDER Bhoost Hosting

Sharing tips and insights on Bhoost and Page Speed Optimization

Leave a Reply

Your email address will not be published.