Fatal error: Uncaught exception 'RedisException' with message 'Redis server went away'
Seeing a stack trace like Fatal error: Uncaught exception 'RedisException' with message 'Redis server went away' is an immediate red flag. It indicates that the PHP process lost its connection to the Redis server while trying to execute a command, specifically in your case during an authentication attempt ($redis->auth). The fact that you have already reinstalled redis-server without success suggests this isn't a simple missing binary issue; it is likely a configuration mismatch, a resource exhaustion event, or a network topology problem within your environment.
When the error occurs inside /var/www/_slim/_core/system/generator.001.php:133, the application is attempting to authenticate with a specific password (77B1BFFBC0378DF...). The phrase "server went away" is generic; it usually means the TCP connection was reset (RST) or closed (FIN) by the server side before the client could read the response.
Investigating Memory and Timeouts
The most common culprit for this specific error is Redis running out of memory (OOM Killer) on the host machine. If your redis-server instance hits its memory limit, the Linux kernel's OOM killer might terminate the redis-server process abruptly. When PHP tries to send an auth command milliseconds later, the server is gone, resulting in this exception.
To verify this, check the system logs for Redis crashes:
journalctl -u redis.service --no-pager | grep -i "out of memory"
# Or if using a manual installation:
dmesg -T | grep -i "kill.*redis"
If you see evidence of the process being killed, you need to either increase available RAM or limit Redis's maxmemory policy in your redis.conf. Setting maxmemory-policy to something like allkeys-lru or volatile-lru can prevent uncontrolled memory growth, though for authentication errors specifically, ensure Redis isn't dying due to a sudden spike in eviction.
Another frequent cause is the timeout setting on the client side versus the server's latency. If your PHP application is running on a different network interface or container than Redis, packet loss or firewall rules dropping idle connections can trigger this. Check your redis.conf for tcp-backlog and ensure bind addresses allow communication between the app and DB nodes.
Connection Pooling and Idle Closures
In high-traffic environments, connection pools are standard practice. If your application uses a pool (like via Predis or PhpRedis), an idle connection might be dropped by the server if it exceeds its timeout threshold. Redis has a timeout configuration directive (often defaulting to 0, meaning no timeout). However, load balancers or firewalls in between often have stricter timeouts (e.g., 30 seconds).
If your PHP script holds a connection open for an extended period during complex generator logic, and the network layer drops it, the next auth() call will fail with "server went away." You must ensure your client library handles reconnection gracefully. In PhpRedis, this often requires checking $redis->ping() before executing critical commands or configuring the pool to refresh connections on failure.
Authentication Specifics
Your stack trace highlights the auth command failing. Redis v6+ introduced stricter handling of authentication and can reject connections if the password hash doesn't match or if ACLs are misconfigured. If you recently updated Redis, ensure your application is using the correct authentication method (ACL vs standard password). A mismatch here might cause the server to immediately close the connection upon receiving the auth request, triggering the "went away" error before the client can parse a standard error response.
Debugging Steps Summary
- Check System Logs: Look for OOM kills or
redis-serverrestarts in/var/log/syslogorjournalctl. - Verify Network Path: Ensure no firewall rules are dropping idle connections between the PHP worker and Redis.
- Test Connectivity Independently: Run a standalone
redis-cli -c -a YOUR_PASSWORD pingfrom the same machine running PHP to isolate if it's an application-level timeout or a server crash. - Review Redis Config: Confirm
bind,protected-mode, andtimeoutsettings match your deployment architecture.
If you are building on top of Laravel, ensure your configuration file isn't forcing a specific serialization format that conflicts with newer Redis versions, though this is less likely to cause an immediate disconnect. For robust solutions in larger deployments, consider using a dedicated connection manager that handles exponential backoff retries when the "server went away" exception is caught.