A symptom that leads you astray
A client sent a screenshot: a blank page and the message “There has been a critical error on this website”. The URL pointed to an ordinary FAQ page. She added: “but after a refresh it worked fine”.
That last sentence matters most – and misleads most. If a refresh fixes it, the code must be fine, right? And if the code is fine, it is probably memory or database queries. That is exactly the path I took, and it cost me time.
So here is the conclusion first, in case it saves someone that detour: a WordPress critical error often does not come from your code. It comes from something your code merely has to handle – and handles badly.
First hypothesis. Wrong one
The page that failed had an unbounded query in its template – fetching every entry in a collection, full content included, to build a sidebar menu. A textbook candidate for memory exhaustion.
It sounded right. It matched the symptom: the first visit generates the page and dies, the second one is served from cache and works.
I fixed that query, because it genuinely was wasteful – only the ID of each post was ever used, yet whole posts were being loaded. But that was an optimisation, not a fix. The real cause was elsewhere, and only the logs showed it.
Server logs say it plainly
Hosting collects error logs on its own, without enabling anything in WordPress. Worth remembering before you start adding WP_DEBUG_LOG to your config – often the file is already waiting in the hosting panel.
In the log from the day of the outage, at one specific minute, sat this:
Predis\Connection\ConnectionException: Connection timed out
[tcp://redis-xxx.hosting.pl:13041]
The Redis cache server stopped responding for a moment. Nothing unusual – networks hiccup. The problem is what happened next.
Why a timeout takes down the whole site
Redis Object Cache, seeing no connection, tries to display an error message. To display a message it needs translations. To load translations it asks for site options. And site options are read through… the cache object that does not exist, because the connection just failed.
handle_exception()
-> show_error_and_die()
-> load_textdomain()
-> get_option('WPLANG')
-> wp_cache_get()
-> Call to a member function get() on null
A second error, this one fatal, while handling the first. That is what kills the page – not the timeout itself. WordPress had not produced a single line of HTML yet, so the visitor gets a bare white screen.
Hence the apparent randomness. A timeout lasts seconds. Whoever lands during it sees the error. Whoever refreshes five seconds later sees a normal page. Nothing needs fixing for it to “work again by itself”.
One line that closes it
In wp-config.php, before the “That’s all, stop editing” line:
define('WP_REDIS_GRACEFUL', true);
From then on, when Redis is unreachable, the plugin quietly falls back to plain in-memory caching. The page loads, and the visitor notices nothing beyond a slightly slower response.
Worth knowing what this line does not do: it does not fix Redis. If the cache server times out regularly, that is a separate problem and the host needs to hear about it. The setting only stops a cache outage from being a site outage.
What stays for next time
A few things worth remembering the next time something “dies every now and then”:
- Logs first, hypotheses second. I spent time analysing code that had nothing to do with the outage. The log had the answer in one line.
- Hosting logs are not WordPress logs. The hosting panel often has files ready to download – faster than configuring debug logging.
- Look for what is missing from the log. The word “memory” never appeared, even though the symptom looked exactly like memory exhaustion. That ruled out the hypothesis faster than any test.
- A plugin handling infrastructure can be more dangerous than the infrastructure. Redis was entitled to stall. Turning that stall into a white screen was the plugin’s design decision.
The improved query stayed in the code, even though it was not the culprit. Since it was loading whole posts where a single ID was used – no reason to keep doing that.



