1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

APC and caching

Discussion in 'Server Configuration and Hosting' started by RobParker, Apr 4, 2012.

  1. RobParker

    RobParker Well-Known Member

    I was wondering if someone could explain how I shoud go about utilising APC for caching.

    I've seen a few contradictory bits of advice so I'm a bit confused.

    Will APC "just work" without doing anything or do I need to add anything to my xf config file?
  2. Floris

    Floris Guest

    It will work out of the box, because just having APC on the server for PHP will mean it attempts to cache your PHP stuff. Yay.

    Additionally you can optimize this for XenForo by updating your config.php file.
  3. RobParker

    RobParker Well-Known Member


    Do you mean my APC config file or my XF one?
  4. Adam Howard

    Adam Howard Well-Known Member

    For your config.php

    ## 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' => 'xf'
    $config['cache']['backend'] = 'Apc';
    I kept my cache id prefix short as to improve load and naming resolve resources. You could name it to anything really, but the shorter the better.

    You shouldn't have the need to change anything in your APC config file, but if you want to try something new and have at least 2GB of ram

    I found this post most useful
  5. RobParker

    RobParker Well-Known Member

    Thanks, that's what I meant about conflicting advice. Kier's post previously said APC will just work but then there's other posts like the one you quote above so I was a bit confused regarding what was really needed.

    Kier said previously that: I'd like to make myself clear on this - I personally do not recommend that you use APC for shared memory caching via your config file.

    Isn't that what you've just done above?
    gasg likes this.
  6. Adam Howard

    Adam Howard Well-Known Member

    You're very much welcome.

    So much information you feel overwhelmed. I can understand that.

    The basic need is only adding it to the config.php file. The link I gave you is good if you want to take it 1 step further.

    The choice is always yours. :)

    (backup always before doing things though)
  7. RobParker

    RobParker Well-Known Member

    Sorry I edited my post while you were replying. Didn't Kier advise NOT to do what you suggest with the config file?
  8. Adam Howard

    Adam Howard Well-Known Member

    I don't think he did and if he did, in my opinion he would be wrong.

    The XenForo manual suggest that you add only

    $config['cache']['backend'] = 'Apc';
    But also goes into detail and admits that it can (will) cause cache slams.

    The code provided in my post, will work without causing any cache slams and has been used on large sites (1,000,000 post) and on my own site as well (100,000 post).
  9. RobParker

    RobParker Well-Known Member


    If I want to enable Fetch public templates as files is the above configuration sufficient?

    It states that:

    For performance reasons, you may choose to have the public-facing side of XenForo load its templates from files rather than the database. Note that in order for this to be of benefit, you must have an opcode cache installed on your server (APC, eAccelerator, XCache etc.)
  10. CyclingTribe

    CyclingTribe Well-Known Member

    Yes, with APC now installed you can load templates as files. :)
  11. RobParker

    RobParker Well-Known Member


    At the minute my server load seems quite a bit higher than it used to on VB :-(

    It hovered around 0.4 most of the time but on XF it's at around 1-1.5. I'm hoping this is just the fact that it's new and not yet cached locally for our visitors and should level out.

    Are there any other "easy" optimisations?
  12. Ghan_04

    Ghan_04 Active Member

    What process is using the CPU? Check top to see where the load is coming from.
  13. Adam Howard

    Adam Howard Well-Known Member

    At your command prompt type the following


    If this command is not understood, do the following

    Cent OS = yum install htop

    Debian or Ubuntu = aptitude install htop

    Then type this command


    This will show you what is using so much CPU and Ram. Please report back
  14. Floris

    Floris Guest

    XenForo's config.php file.
  15. mrGTB

    mrGTB Well-Known Member

    Something I spotted, think your missing an underscore line in your prefix like so below.

    TheVisitors likes this.
  16. RobParker

    RobParker Well-Known Member

    Output from top

    Screen Shot 2012-04-07 at 14.57.02.png

    Most of the day the load has been around 0.8 or so but just had a bit of an increase due to traffic.

    Even then we only had 500 users online (half guests) and VB was able to cope with several thousands.
  17. CyclingTribe

    CyclingTribe Well-Known Member

    Have you accounted for Google reindexing your entire site?

    Also check for Baidu spider too (Chinese search engine) - I was seeing a massive spike which disappeared when I blocked Baidu (added their spider IPs to my firewall).

    Just a thought ... :)
  18. RobParker

    RobParker Well-Known Member

    That's a good point. I'd thought about the re-caching but not the re-indexing.

    Is there a simple way to check for spiders?
  19. Floris

    Floris Guest

    Block baidu, ... because nobody cares about it except SEO spammers and chinese government.
  20. RobParker

    RobParker Well-Known Member

    APC is working but we seem to be getting far more cache requests than we used to and this looks a bit suspicious.

    Screen Shot 2012-04-09 at 16.55.40.png

    Anything to be worried about?

Share This Page