Magento Expert Forum - Improve your Magento experience

onet connect
Results 1 to 3 of 3

Speeding up Magento with APC or Memcached

  1. #1
    Junior Member sgdev's Avatar
    Join Date
    Apr 2013
    Thanked 1 Time in 1 Post

    Post Speeding up Magento with APC or Memcached

    We often hear complaints about how Magento is slow and performs poorly. Developers know, however, that performance is relative and that we can do a number of things to speed up a Magento site. This article will focus on configuring and using APC and/or Memcached. We have a resources section at the end of this article with links to more performance optimization techniques.

    The options obviously also depend on the specific hosting arrangement. I will assume for the purposes of this article, that you have control over your hosting server and are able to install the necessary add-ons and make configuration changes to Apache and PHP. If you are on a shared environment, you may have to check with your hosting support if you can apply the tips from this article. But, you know that you should at least be on a VPS if you are running Magento.

    APC – Alternative PHP Cache

    Using APC is really easy. You can just install the PHP module and restart your Apache server and your sites should immediately benefit from this.

    To install APC on a Debian based Linux distro, run:

    sudo apt-get install php5-apc
    Note that you will need either root or sudo privileges to perform the install
    Then just restart your Apache server. You should start seeing improvements after browsing to a few pages on your site.

    This is great already, however, there is another step you can do to integrate APC with your Magento site.

    If you look at: app/etc/local.xml.additional, you will notice that there is a <cache> element that allows you to specify which caching method you are using in the <backend> element. This can have one of the following values:

    • apc
    • memcached
    • xcache

    We are dealing with APC here so we’ll just add:

    HTML Code:
    This is the recommended entry from the Understanding Magento Scalability and Performance Magento blog post.

    You will notice the <prefix> element containing MAGE_. This is simply a prefix to tell APC what to use when it creates the cache. This is particularly important if you are running several Magento sites on the same web server. In this case, you will need to enter a unique prefix for each site. For example:

    Site A

    HTML Code:
    Site B

    HTML Code:
    Finally, to put the polish on your speed improvements, you can also tweak the APC configuration to further optimize your cache. This is done by editing the apc.ini file usually located (on Debian based distros) in: /etc/php5/conf.d/apc.ini.

    We will recommend this APC configuration that was posted in the official Magento forums.

    extension =    #name dependent on your APC cache install
    apc.enabled = 1    # Turn APC cache on
    apc.optimization  = 0    # Experimental keep off
    apc.shm_segments = 1    # Shared memory segments
    apc.shm_size = 128  # Max shared memory dependent on OS
    apc.ttl = 7200
    apc.user_ttl  = 7200
    apc.num_files_hint = 1024
    apc.mmap_file_mask = /tmp/apc.XXXXXX
    apc.enable_cli = 1 # Allow command line php to function
    apc.cache_by_default  = 1 # Enabled, 0 for filters
    apc.max_file_size = 10M # Maximum cached file size
    apc.stat = 1 # 1 for dev, 0 for production, whether the source file is checked for mod date
    #apc.include_once_override = 1 # Use PHP5.3+ for include_once optimization
    Make sure you remove all the # comments from your real file as stated in the corresponding forum post.

    Of note is the apc.shm_size parameter. By default it is only 32M so the recommendation is to increase it to 128M. However, be careful if you are on a VPS with limited RAM, often you only have 384M or 512M so you may need to reduce your value to 64M. Especially if you want to combine this optimization technique with optimizing the MySQL parameters which also usually require increasing values for memory usage.


    Memcached is a free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

    Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

    Magento supports Memcached out of the box but by default, it is not enabled since we can’t assume that your server will have all the prerequisites installed.

    To enable Memcached you will need to check if the daemon is running. By default the daemon is configured to listen to port 11211 so you can perform a netstat command and see if there is activity on 11211. If it’s running, you need to check if Memcached PHP support is enabled by looking at the output of phpinfo().

    Once again, if you need to install the necessary components, on a Debian type distro the commands are something like:

    sudo apt-get install memcached php5-memcache
    You’ll need to enable Memcached via its configuration file (there will be a notice about this when you run the above command). Then start the service and restart Apache.

    After this, you can add the following <cache> section to your app/etc/local.xml:

    HTML Code:
    These settings are for a single local server running Memcached on the default 11211 port.

    To see your Memcached in action you can issue a telnet localhost 11211 command and type: stats

    View more threads in the same category:

  2. #2
    Administrator david's Avatar
    Join Date
    Nov 2012
    Thanked 37 Times in 31 Posts


    For dynamic cache magento, we have popular choices are: APC, Memcached, Redis. Here is instruction for redis if you want to make magento site faster because redis support tags caching what improve speed a lot for magento caching core. View thread here Redis Caching Configuration for Magento

  3. #3
    New member Ritvars Radvilavičs's Avatar
    Join Date
    Oct 2014
    Leicester, UK
    Thanked 0 Times in 0 Posts


    Which Debian version are you working with and would suggest?
    Which one is better and why?
    Which of these Debian configurations can work with Nginx + Percona XtraDB + Amazon AWS + Redis + Varnish + PHP-FPM ?

    1.Debian Wheezy 64 bit minimal system, only SSH is installed.

    2. Debian Squeeze 64 bit + Confixx 3.3.X on Debian Squeeze 64bit base with pre-installed Parallels Confixx 3.3.9. (excl. Royalty!)

    3. Debian Wheezy 64 bit Debian Wheezy + Froxlor on 64bit base is installed and pre-configured Froxlor.

    4. Debian Wheezy 64 bit + i-MSCP Debian Wheezy 64bit on base with pre-installed i-MSCP Control Panel

    5. Debian Squeeze 64 bit + ispCP on Debian Squeeze 64bit base with pre-installed ispCP 1.1.0 Beta first

    6. Debian Wheezy 64 bit + Plesk 12.x Debian Wheezy 64bit on base with pre-installed Parallels Plesk 12 (excl. Royalty!)

    7. Debian Wheezy + OpenVPN Access Server Debian Wheezy 64bit on base with pre-installed OpenVPN Access Server (incl. 2 user license)

    8. Debian Squeeze 64 bit + ownCloud Debian Squeeze on 64bit base is installed and preconfigured ownCloud.

    9. Debian Squeeze 64 bit minimal system, only SSH is installed.

    Appreciate professional and experienced replies, thank you!

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts