Welcome to Centmin Mod Community
Become a Member

Xenforo Optimising an caching XF

Discussion in 'Forum software usage' started by viralpoet, Mar 5, 2017.

  1. viralpoet

    viralpoet Member

    43
    3
    8
    Mar 5, 2017
    Ratings:
    +9
    Local Time:
    2:05 PM
    1.10.3
    10
    I've come from vpssim running xenforo with nginx, front end caching, back end memcached and opcache on the php files. It was quite well optimised, but now I need to change that to run under Centmin.


    I've noticed a few posts on caching and optimisation of XF, with Centmin but they are a little older. Whats the best optimisation now? I need it to work well as my servers are US, and the community is NZ based.

    Thanks also for the XF2 install - I can't belive how simple you made the whole process for me to follow.
     
  2. eva2000

    eva2000 Administrator Staff Member

    55,811
    12,273
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,859
    Local Time:
    12:05 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yup if you're playing with Xenforo 2.0 Dev Preview releases, you'd want to read https://community.centminmod.com/posts/45274/ which will be updated as Xenforo 2.0 development goes on :)

    For Xenforo 1.5.x caching, PHP 5.6+ has Zend Opcache for opcode caching which is automatic so nothing to configure. For backend caching for Centmin Mod you have choices of:
    1. Memcached server is already installed by Centmin Mod
    2. Redis server caching and instructions on how to install Redis server (1st post).

    Xenforo Libmemcached/Memcached server backend cache



    For Centmin Mod LEMP web stack powered Xenforo forum which has Libememcach/Memcached PHP extension and Memcached server installed out of the box.

    As per official Xenforo manual, within your Xenforo library/config.php add or alter settings to the following, caching the cache_id_prefix value from xfxx_ to a unique one to each Xenforo installed instance on your server. So your library/config.php would have something like
    PHP:
    $config['cache']['enabled'] = true;
    $config['cache']['cacheSessions'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array(
    'caching' => true,
    'cache_id_prefix' => 'xfxx_',
    'automatic_serialization' => false,
    'lifetime' => 0
    );

    $config['cache']['backend'] = 'Libmemcached';

    $config['cache']['backendOptions'] = array(
    'servers' => array(
    array(
    'host' => '127.0.0.1',
    'port' => 11211,
    'weight' => 1
    )
    )
    );

    Xenforo Redis Cache Server backend cache via Zend Redis Cache Xenforo Addon



    For Centmin Mod LEMP web stack powered Xenforo forum which has Redis server support via REMI Yum repository installation and out of box Redis PHP extension support as outlined above. Be sure to install the Zend Redis Cache Xenforo Addon by Xon for this to work.

    You'll need to setup Redis server /etc/redis.conf as a LRU cache as outline at Using Redis as an LRU cache – Redis and in above 1st post. Basically. in /etc/redis.conf set a memory limit, eviction policy and LRU algorithm sample size.

    Example with 100MB max memory limit for Redis used as a LRU cache
    Code (Text):
    maxmemory 100mb
    maxmemory-policy allkeys-lru
    maxmemory-samples 10


    restart Redis server after making changes to /etc/redis.conf config file
    Code (Text):
    service redis restart


    As per FAQ Zend Redis Cache - FAQ | XenForo Community

    Within your Xenforo library/config.php add or alter settings to the following, caching the cache_id_prefix value from xfxx_ to a unique one to each Xenforo installed instance on your server

    PHP:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'xfxx_';
    $config['cache']['backend'] = 'Redis';
    $config['cache']['backendOptions'] = array(
           
    'server' => '127.0.0.1',
           
    'port' => 6379,
           
    'database' => 1,
           
    'connect_retries' => 2,
           
    'use_lua' => true,
           
    'compress_data' => 2,
           
    'read_timeout' => 1,
           
    'timeout' => 1,
       );
    require(
    XenForo_Application::getInstance()->getConfigDir().'/SV/RedisCache/Installer.php');
    Ensure to flush Redis server cache after change

    To flush all redis databases
    Code (Text):
    redis-cli FLUSHALL
    

    To flush just database 8 if you set it differently from default database 0
    Code (Text):
    redis-cli -n 8 flushdb


    You may need to re-login to your Xenforo forum. Browse your forums to populate the Redis cache and then check via PHP Redis Admin for database 0 or database 1 cache entries.
     
    Last edited: Mar 6, 2017
  3. Jon Snow

    Jon Snow Active Member

    861
    174
    43
    Jun 30, 2017
    Ratings:
    +268
    Local Time:
    11:05 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    @eva2000 how do you flush Libmemcached? Only way from that post was for Redis :bookworm:
     
  4. dcg

    dcg Member

    67
    24
    8
    Oct 17, 2015
    Florida, USA
    Ratings:
    +49
    Local Time:
    10:05 PM
    1.21.x
    10.3.x
    Try this
    Code:
    memflush --servers=localhost:11211
    This will flush the whole memcache server fyi
     
    Last edited: Jan 5, 2018
  5. eva2000

    eva2000 Administrator Staff Member

    55,811
    12,273
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,859
    Local Time:
    12:05 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  6. Jon Snow

    Jon Snow Active Member

    861
    174
    43
    Jun 30, 2017
    Ratings:
    +268
    Local Time:
    11:05 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    @dcg Will it have any output? It didn't for me but I'm guessing it did its job.
     
  7. dcg

    dcg Member

    67
    24
    8
    Oct 17, 2015
    Florida, USA
    Ratings:
    +49
    Local Time:
    10:05 PM
    1.21.x
    10.3.x
    @eva2000 I use to just restart but at if a program was looking for the server at that time it would throw an error. Just found this to be a bit cleaner.

    @Jon Snow correct no output. But I like to use the memcache_ monitor page located here: /usr/local/nginx/html/
    Username and Password are located in the head of file.

    There is notes on it here: PHP Opcode and Memcached statistics pages

    Memcached - located at /usr/local/nginx/html/memcache_${N}.php where ${N} is randomised number unique to each Centmin Mod installation. So to access this file you would go to hostname.yourdomain.com/memcache_${N}.php. You can change the file name or location if you want after install. Memcached statistics page has an auto generated username and password unique to each Centmin Mod install which is printed out at end of the Centmin Mod initial install output. If you missed that info, you can find the username and password located in your Centmin Mod initial install log at /root/centminlogs/centminmod_1.2.3-eva2000.07_DDMMYY-TIMESTAMP_install.log. You can use grep to easily find the relevant part of the install log containing the user/pass details:
    Code:
    grep -A13 'Setup memcached_' /root/centminlogs/centminmod_1.2.3-eva2000.07_DDMMYY-TIMESTAMP_install.log
    
     
  8. eva2000

    eva2000 Administrator Staff Member

    55,811
    12,273
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,859
    Local Time:
    12:05 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yeah true
     
  9. dcg

    dcg Member

    67
    24
    8
    Oct 17, 2015
    Florida, USA
    Ratings:
    +49
    Local Time:
    10:05 PM
    1.21.x
    10.3.x
    I forgot to mention you can also flush from that memcache stats page I mentioned.