- License Information
- Compatible XF 2.x versions 2.1 2.2
Additional requirements php 7.0+
Redis (v3.0.0 or better)
phpredis (for performance)
GitHub Page:GitHub - Xon/XenForo2-RedisCache: XenForo2 + Redis + Glue code
XenForo2 + Redis + Glue code. Contribute to Xon/XenForo2-RedisCache development by creating an account on GitHub.github.com
- Developer
- Xon
This add-on uses Credis with a custom cache provider for Redis (based off Cm_Cache_Backend_Redis). For best performance, install the php extension: phpredis
You must have a Redis instance installed, this is likely not possible with shared hosting
While XenForo 2 has a redis connector, it requires phpredis. This add-on does not.
Feature overview
Please be aware that Redis is very sensitive to latency in a virtual environment. If repeated connection failures or protocol errors are experienced disable any Redis Persistence options.
Options
By default, forum thread counts are cached. In general, this is observable when moving large number of threads from one forum to another, and the total page counts are wrong.
Redis Statistics
Admincp dash board is extended with basic redis statistics:
Read Scaling
With the
See the FAQ for configuration samples.
High availability
The Zend component support master/slave setups with Redis Sentinel support. It does not support Redis multi-master clustering.
Components licenced under; New BSD
Please create a GitHub Pull request via the "More Information" link.
FAQ
Q: There are a lot of the errors; "CredisException: read error on connection" or "CredisException: protocol error, got 'xxx' as reply type byte" being logged
A: Please be aware that Redis is very sensitive to latency in a virtual environment. If repeated connection failures or protocol errors are experienced disable any Redis Persistence options. Additionally, check CPU steal as this can also cause latency issues.
Additionally, check the redis log file ( /var/log/redis/redis.log ) for any warnings. Key things to look for:
You may require to adjust "net.ipv4.tcp_max_syn_backlog" to be larger!
(All 'fixes' require restarting redis to apply).
You may need to increase tcp-backlog from the stock 511, please ensure net.core.somaxconn is adjusted as well!
This server configuration advise is best effort, and not guarantied as it is well outside the scope of this add-on.
Q. CPU Steal is mentioned as causing latency issue, how do I check this.
A. On Linux, run:
Then after a day or so; check your max CPU steal:
Q: Support for earlier versions of XenForo
A: See Zend Redis cache add-on for XenForo 1.4+ support
Q: Redis Configuration
A: Please see the Redis Documenatation.
Alternatively, you can use @eva2000's How to install Redis server on Centmin Mod LEMP stack Guide.
Q:Make Redis behave like Memcache
A: See Using Redis as an LRU cache, and make sure to set maxmemory!
ou may wish to disable the periodic 'save' directives which can cause latency on high-usage websites in virtual environments.
Q: Sample XenForo Configuration using TCP
A: Please see https://xenforo.com/xf2-docs/manual/cache/ for details on setting up the general XenForo Cache.
The minimum configuration is:
Q: Sample XenForo Configuration using a socket
A: Please see https://xenforo.com/help/cache/ for details on setting up the general XenForo Cache.
The minimum configuration is:
Q: Sample XenForo Configuration using username/password
Redis supports username/password authentication.
This is most common in cloud environments which use redis 6 (ie with a username), while older redis only supports just a password
Q. Sample XenForo Configuration using SSL/TLS support
Q. When trying to use a socket, an exception with "No such file or directory" is thrown
A. There are a few reasons this could happen;
After confirming that the socket path is correct, try the following suggestions:
A:
The minimum configuration is:
Q: Sample Redis Sentinel Configuration
A:
Redis Sentinel support for high-availability. See http://redis.io/topics/sentinel for more information.
Enable with:
'server' now points to a comma delimited list of sentinel servers to find the master. Note; the port must be explicitly listed
To load data from slaves use;
By default, a local slave is preferred, this can be changed by setting:
Setting to false (or some non-callable) will fall back to a random slave.
Q: Performance - Redis
A: See:
Q: phpredis supports persistent connection, are these recommended?
A: I do not recommend using persistent connections, as they appear to be quite buggy.
You must have a Redis instance installed, this is likely not possible with shared hosting
While XenForo 2 has a redis connector, it requires phpredis. This add-on does not.
Feature overview
- A pure php redis connector
- High availability support
- Exposes redis cache object for use for use by other add-ons
- Implements some minor caching of forum thread counts
- Redirect's XenForo's individual css template caching to hit redis as otherwise it causes unexpected write & deadlocking on the xf_css_cache table
Please be aware that Redis is very sensitive to latency in a virtual environment. If repeated connection failures or protocol errors are experienced disable any Redis Persistence options.
Options
By default, forum thread counts are cached. In general, this is observable when moving large number of threads from one forum to another, and the total page counts are wrong.
Redis Statistics
Admincp dash board is extended with basic redis statistics:
Read Scaling
With the
$config['cache']['config']['load_from_slave']
option, reads can be deferred to a singular slave instance. This takes all the options of 'config' (except the slave config)See the FAQ for configuration samples.
High availability
The Zend component support master/slave setups with Redis Sentinel support. It does not support Redis multi-master clustering.
- Additionally, this add-on implement caching of thread counts in a forum.
- Redis Sentinel support for high-availability (see FAQ for details).
Components licenced under; New BSD
- Credis
- XenForo Add-on code
Please create a GitHub Pull request via the "More Information" link.
FAQ
Q: There are a lot of the errors; "CredisException: read error on connection" or "CredisException: protocol error, got 'xxx' as reply type byte" being logged
A: Please be aware that Redis is very sensitive to latency in a virtual environment. If repeated connection failures or protocol errors are experienced disable any Redis Persistence options. Additionally, check CPU steal as this can also cause latency issues.
Additionally, check the redis log file ( /var/log/redis/redis.log ) for any warnings. Key things to look for:
- WARNING you have Transparent Huge Pages (THP) support enabled in your kernel
Transparent Huge Pages fix
Run:
Add to /etc/rc.local
Run:
Code:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
Code:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
- WARNING /proc/sys/net/core/somaxconn is set to the lower value of 128
somaxconn fix
Run:
Add to /etc/sysctl.d/redis.conf (or /etc/sysctl.conf)
Run:
Code:
sysctl -w net.core.somaxconn=512
Code:
net.core.somaxconn=512
- WARNING overcommit_memory is set to 0! Background save may fail under low memory condition
overcommit fix
Run:
Add to /etc/sysctl.d/redis.conf (or /etc/sysctl.conf)
Run:
Code:
sysctl -w vm.overcommit_memory =1
Code:
vm.overcommit_memory =1
(All 'fixes' require restarting redis to apply).
You may need to increase tcp-backlog from the stock 511, please ensure net.core.somaxconn is adjusted as well!
This server configuration advise is best effort, and not guarantied as it is well outside the scope of this add-on.
Q. CPU Steal is mentioned as causing latency issue, how do I check this.
A. On Linux, run:
Code:
screen
iostat -c -t 30 > /tmp/cpu_stats.log
Then after a day or so; check your max CPU steal:
Code:
cat /tmp/cpu_stats.log | grep -v iowait | awk '{print $5;}' | sort -rn | more
Q: Support for earlier versions of XenForo
A: See Zend Redis cache add-on for XenForo 1.4+ support
Q: Redis Configuration
A: Please see the Redis Documenatation.
Alternatively, you can use @eva2000's How to install Redis server on Centmin Mod LEMP stack Guide.
Q:Make Redis behave like Memcache
A: See Using Redis as an LRU cache, and make sure to set maxmemory!
Code:
maxmemory 256mb
maxmemory-policy allkeys-lru
ou may wish to disable the periodic 'save' directives which can cause latency on high-usage websites in virtual environments.
Q: Sample XenForo Configuration using TCP
A: Please see https://xenforo.com/xf2-docs/manual/cache/ for details on setting up the general XenForo Cache.
The minimum configuration is:
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => 6379,
];
Q: Sample XenForo Configuration using a socket
A: Please see https://xenforo.com/help/cache/ for details on setting up the general XenForo Cache.
The minimum configuration is:
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
'server' => 'unix:///tmp/redis.sock',
];
Q: Sample XenForo Configuration using username/password
Redis supports username/password authentication.
This is most common in cloud environments which use redis 6 (ie with a username), while older redis only supports just a password
Code:
$config['cache']['config']['username'] = 'myUsername'; // requires redis 6+, or for cloud redis installations
$config['cache']['config']['password'] = '....';
Q. Sample XenForo Configuration using SSL/TLS support
PHP:
$config['cache']['config']['server'] = 'ssl://127.0.0.1';
// See https://www.php.net/manual/en/context.ssl.php for details
$config['cache']['config']['tlsOptions'] = [
'SNI_enabled' => true,
];
Q. When trying to use a socket, an exception with "No such file or directory" is thrown
A. There are a few reasons this could happen;
After confirming that the socket path is correct, try the following suggestions:
- selinux is preventing php from accessing the socket.
- open_basedir is preventing php from accessing the socket.
- chroot is preventing php from accessing the socket.
- permissions are preventing php from reading/writing to the socket.
A:
The minimum configuration is:
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => 6379,
];
$config['cache']['config']['load_from_slave'] = array(
'server' => '127.0.0.1',
'port' => 6378,
];
Q: Sample Redis Sentinel Configuration
A:
Redis Sentinel support for high-availability. See http://redis.io/topics/sentinel for more information.
Enable with:
Code:
$config['cache']['config']['sentinel_master'] = 'mymaster';
$config['cache']['config']['server'] = 'tcp://127.0.0.1:26379';
'server' now points to a comma delimited list of sentinel servers to find the master. Note; the port must be explicitly listed
To load data from slaves use;
Code:
$config['cache']['config']['load_from_slaves'] = true;
By default, a local slave is preferred, this can be changed by setting:
Code:
$config['cache']['config']['slave_select_callable'] = function (array $slaves) {
$slaveKey = array_rand($slaves, 1);
return $slaves[$slaveKey];
};
Setting to false (or some non-callable) will fall back to a random slave.
Q: Performance - Redis
A: See:
Q: phpredis supports persistent connection, are these recommended?
A: I do not recommend using persistent connections, as they appear to be quite buggy.