1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

[Tip] Use APC

Discussion in 'Tips and Guides [Archive]' started by Floris, Oct 14, 2010.

  1. Floris

    Floris Guest

    Original article: http://xenfans.com/threads/tip-use-apc.94/

    Make a new file called apc-test.php with inside it the following code:
    and run it from the browser. Search for the APC block, if you can't find it or it reports as disabled, then I strongly recommend either installing it, or enabling it.

    APC: http://php.net/manual/en/book.apc.php

    The Alternative PHP Cache (APC) is recommended by XenForo Limited, and after running XenForo alpha and beta for a while and then turning it on, I can tell you: they are right.
    • Pages load snappy, as if they are run from localhost.
    • The server load goes down.
    The above two points are the main two reasons why I run it.

    Running vBulletin on the same server showed a load between 0.25 to 0.50.
    Running XenForo on the same server (after import) showed a load between 0.15 and 0.35.
    Running XenForo with APC on the same server showed a load between 0.05 and 0.15.

    I can imagine that bigger sites will benefit even more.

    It might be obvious to some, but easily overlooked by others. So I thought it was worth reminding people to consider using APC in order to make the most of their XenForo installation.

    And now for the XenForo part :) Update the library/config.php with these values:

    ## Caching
    #  http://xenforo.com/community/threads/speed-up-your-board-caching.5699/
    #  http://xenforo.com/community/threads/tip-use-apc.6456/
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array(
    'caching'                      => true,
    'automatic_serialization'      => true,
    'lifetime'                      => 10800,
    'cache_id_prefix' => 'foro'
    $config['cache']['backend'] = 'Apc';
    Note: The cache_id_prefix is handy if you run more than one instance on the same server. Plus, I still recommend to set one, so it doesn't conflict with whatever else you might be running on the server :)

    Some resources:
    http://google.com (search: how to install apc on <your distro here.)
  2. Andy Huang

    Andy Huang Well-Known Member

    Might be redundant, but I suppose this is a good place to mention the instructions of how to enable APC on your XenForo installation. To enable APC on your installation, after you have APC installed and configured, simply add these to your config.php file in library folder:
    ## Caching
    #  http://xenforo.com/community/threads/speed-up-your-board-caching.5699/
    #  http://xenforo.com/community/threads/tip-use-apc.6456/
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array(
    'caching'                       => true,
    'automatic_serialization'       => true,
    'lifetime'                      => 10800
    $config['cache']['backend'] = 'Apc';
    "lifetime" is how long your entries should be cached. You can adjust 10800 to the number of seconds that matches your preference.
    silendreamer and Pyro like this.
  3. ragtek

    ragtek Guest

    You should also enabpe apc in the config.php

    Oh, andy was faster
  4. Andy Huang

    Andy Huang Well-Known Member

    Ninja'ed ;)
  5. Brogan

    Brogan XenForo Moderator Staff Member

    Nice tip.

    Just checking with my host now why they don't have APC enabled.
  6. Andy Huang

    Andy Huang Well-Known Member

    If you're on a shared hosting, they most likely won't have it enabled because of name space reasons (IE: Oh, but johndoe123 thinks xf_data_bannedIps should include *), and they're most likely not ready to share 32m of ram with each and every customers on that server. If you're on a VPS or a dedicated server, then installing it shouldn't be too complicated (pecl is your friend if you're lazy like me :D)
  7. Brogan

    Brogan XenForo Moderator Staff Member

    Spot on.
    Shared server so they can't/won't implement it due to load.
  8. Shamil

    Shamil Well-Known Member

    Load? I've never seen APC increasing load, even in a busy shared hosting environment.
  9. Ranger375

    Ranger375 Well-Known Member

    What would you all recommend? I currently have suPHP and cant use APC with it. Is disabling suPHP and installing APC the way to go?
  10. DSF

    DSF Well-Known Member

    APC is enabled now with default settings.
    Load will decreasing by factor 3 to 4 :)
  11. Floris

    Floris Guest

    I just noticed that my block of 'updating xenforo config.php' didn't make it to the copy paste! Thanks Andy :)
  12. Floris

    Floris Guest

    Updated first post with new info + andy's block, and extended it with a prefix (very handy!)
  13. Sadik B

    Sadik B Well-Known Member

    Also it would be worthwhile mentioning that on large forums, APC shared memory tends to get fragmented very quickly. Our dedicated server which runs some very busy sites showed 100% fragmentation until we tweaked some APC config values. Mostly the ttl values and shared memory size. I don't have the settings on hand right now, so googling should probably answer that.
  14. Floris

    Floris Guest

    The average for the last 12 hours running ALL my sites on APC (wordpress, 2x xenforo, and a few test vbulletins and some private custom coded php sites, etc)

    12havg : up 106 days, load average: 0.03, 0.23, 0.27

    compared to a couple of days ago without any APC, same setup:

    12havg : up 103 days, load average: 0.24, 0.38, 0.41
  15. Floris

    Floris Guest

    Any cache comes with downsides, such as fragmentation. I would love to get a glimps of the apc configuration tweaks.
  16. Floris

    Floris Guest

    Yep, suPHP is causing more problems than it's worth in my opinion. suhosin default in php = huge fail, in my book.
    Blandt likes this.
  17. Floris

    Floris Guest

    Another reason why I don't like Shared hosting. :)
  18. Andy Huang

    Andy Huang Well-Known Member

    I'm in a major love-hate (more hate than love) relationship with Debian right now, where they package suhosin with their php bundles.
    I know I can compile it myself, but I'm lazy, and I know I can build my own deb, but I'm still lazy.
    Fortunately for me, I'm using it as a test box, so there's no major set-backs leaving suhosin enabled.
    One of these days, I'm going to go and build my own package without suhosin "patch"...
    Blandt likes this.
  19. Deebs

    Deebs Well-Known Member

    Working fine here with

    This server is protected with the Suhosin Patch
    Copyright (c) 2006-2007 Hardened-PHP Project Copyright (c) 2007-2009 SektionEins GmbH
  20. Ranger375

    Ranger375 Well-Known Member

    I'm assuming you're rocking PHP 4 then?

Share This Page