Today I received a message from a friend on WeChat, reminding me that the blog cannot be opened. Sure enough, after opening it, it directly displayed "Your site has encountered a fatal error." If you think about it carefully, in addition to being attacked recently, the blog has installed the W3 Total Cache plug-in. According to speculation, it can basically be concluded that the plug-in is to blame. .

After investigation, it was found that the PHP error was: "Uncaught RedisException: OOM command not allowed when used memory", indicating that Redis cannot write data to the memory, even if the server is restarted. The final solution is to adjust the Redis configuration and increase the default memory size.

This article will share the process of how to troubleshoot that your WordPress site has encountered a fatal error. There are more articles about WordPress website building here:

  1. WordPress all-round and super compatible code highlighting plug-in Enlighter-WP essential plug-in
  2. Poedit, an essential tool for Chineseizing WordPress themes and plug-ins – automatically generates .Po and .Mo files
  3. Use Elasticsearch as WordPress on-site search-docker install elasticSearch, kibana and ik word segmenter

1. Turn on WP Debug mode

When your WordPress encounters an error, don’t panic. Choose to open the Debug mode of WordPress and call the PHP error. Method reference: WordPress error diagnosis mode - specializes in WP page blanks, server 500 errors, and plug-in conflicts.

2. Find WP fatal errors

After turning on the Debug mode of WordPress, the web page will display PHP errors, as follows:

Fatal error: Uncaught RedisException: OOM command not allowed when used memory > 'maxmemory'. in /xxx/wzfou.com/wp-content/plugins/w3-total-cache/Cache_Redis.php:68 Stack trace: #0 /xxxxx/wzfou.com/wp-content/plugins/w3-total-cache/Cache_Redis.php(68): Redis->setex('w3tc_1987146988…', 180, 'a:2:{s: 7:"conte…') #1 /xxxx/wzfou.com/wp-content/plugins/w3-total-cache/ObjectCache_WpObjectCache_Regular.php(293): W3TCCache_Redis->set('0optionsallopti…', Array, 180) # 2 /xxx/wzfou.com/wp-content/plugins/w3-total-cache/ObjectCache_WpObjectCache_Regular.php(388): W3TCObjectCache_WpObjectCache_Regular->set('alloptions', Array, 'options', 0) #3 /xxx/wzfou .com/wp-content/plugins/w3-total-cache/ObjectCache_WpObjectCache.php(77): W3TCObjectCache_WpObjectCache_Regular->add('alloptions', Array, 'options', 0) #4 /xxxx/wzfou.com/wp- content/object-cache.php(95): W3TCObjectCache_WpObjectCache->add('alloptions', Array, 'options', 0) #5 /xxxx/wzfou.com/wp-includes/option.php(258): in /xxxx/wzfou.com/wp-content/plugins/w3-total-cache/Cache_Redis.php on line 68

Error message: "Uncaught RedisException: OOM command not allowed when used memory > 'maxmemory'. in /xxx/wzfou.com/wp-content/plugins/w3-total-cache/Cache_Redis.php", obviously because Redis is turned on Object caching caused the error. Viewed the Redis configuration:

root@localhost:~# redis-cli
127.0.0.1:6379> info memory
# Memory
used_memory:250161160
used_memory_human:238.57M
used_memory_rss:274608128
used_memory_rss_human:261.89 M
used_memory_peak:254227888
used_memory_peak_human:242.45M
used_memory_peak_perc:98.40%
used_memory_overhead:7712830
used_memory_startup:803088
used_memory_dataset:2424 48330
used_memory_dataset_perc:97.23%
allocator_allocated :250366144
allocator_active:260894720
allocator_resident:268197888
total_system_memory:2111430656
total_system_memory_human:1.97G
used_memory_lua:37888
used _memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human :0B
number_of_cached_scripts:0
maxmemory:251000000
maxmemory_human:239.37M
maxmemory_policy:noeviction
allocator_frag_ratio:1.04
allocator_frag_bytes:10528576
alloc ator_rss_ratio:1.03
allocator_rss_bytes: 7303168
rss_overhead_ratio:1.02
rss_overhead_bytes:6410240
mem_fragmentation_ratio:1.10
mem_fragmentation_bytes:24487992
mem_not_counted_for_evict:0
mem_replication_back log:0
mem_clients_slaves:0
mem_clients_normal:390678
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
127.0.0.1:6379>

It can be seen from the configuration: the occupied memory used_memory_human:238.57M, the system allows Redis to use the maximum memory: maxmemory_human:239.37M, it is indeed occupied and the space is gone.

3. Solve the problem of insufficient Redis memory

If you are using Oneinstack, you can refer to the following method to modify the configuration of Redis. By the way, you can also modify the configuration of Memcached to increase the default memory:

#Redis默认端口:6379
#Memcached默认端口:11211
#默认监听地址:127.0.0.1

#调整Redis最大内存大小?

vi /usr/local/redis/etc/redis.conf

maxmemory 1024000000#单位字节,默认1G,可调整

service redis-server restart#重启生效

#增加Memcached最大内存大小?

vi/etc/init.d/memcached

CACHESIZE=256 #单位M,默认256M,可调整

service memcached restart#重启生效

Set elimination policy: maxmemory-policy volatile-lru

Several other elimination strategies are described below:

noeviction

Default policy

Not evicted

When there is not enough memory for Redis to use, an exception will be reported when executing the write command: redis.exceptions.ResponseError,OOM command not allowed when used memory > ‘maxmemory’

volatile-lru

For expired keys, execute the lru elimination strategy (evict the least recently used data)

If there is no expired key, an exception will be reported when executing the write command when the memory is insufficient: redis.exceptions.ResponseError, OOM command not allowed when used memory > ‘maxmemory’, the same as noeviction policy

allkeys-lru

Execute lru for all keys

There is no way to restrict some algorithms to delete certain keys.

If your application needs to persist some data, please do not use the allkeys-lru strategy

volatile-random

For expired keys, randomly select a key to expel

allkeys-random

For all keys, randomly select a key to expel

volatile-ttl

Among expired keys, the one with the smallest ttl value will be evicted first.

4. Summary

WordPress optimization acceleration is a commonplace topic. In order to achieve the best results, we often need to reasonably adjust the optimization strategy based on the actual configuration of our server.

Regarding the optimization and acceleration of the blog, I have written a summary topic: Main application technologies and supporting features of blogs - Summary of website and server optimization methods of the blog.

Leave a Reply