• 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

  • Thread starter Thread starter Floris
  • Start date Start date
F

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:
PHP:
<?=phpinfo();
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.
acpblock.png


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:

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' => '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://framework.zend.com/manual/en/zend.cache.frontends.html
http://howto.techtutz.com/install-apc-10-steps
http://mrfloris.com/vbulletin/installing-apc-on-centos-5-server/
http://google.com (search: how to install apc on <your distro here.)
 
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:
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
);
$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.
 
You should also enabpe apc in the config.php

Oh, andy was faster
 
Nice tip.

Just checking with my host now why they don't have APC enabled.
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)
 
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.
Spot on.
Shared server so they can't/won't implement it due to load.
 
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?
 
I just noticed that my block of 'updating xenforo config.php' didn't make it to the copy paste! Thanks Andy :)
 
Updated first post with new info + andy's block, and extended it with a prefix (very handy!)
 
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.
 
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
 
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.

Any cache comes with downsides, such as fragmentation. I would love to get a glimps of the apc configuration tweaks.
 
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?

Yep, suPHP is causing more problems than it's worth in my opinion. suhosin default in php = huge fail, in my book.
 
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"...
 
Top Bottom