PHP Redis 错误:未捕获的异常“RedisException”


PHP Redis Error: Uncaught exception ‘RedisException’

我使用Redis构建一个IOS SNS应用程序(用于restful api)。随着越来越多的用户使用它,错误发生了。

它抛出:

Uncaught exception 'RedisException' with message 'read error on connection' 
in /data1/www/htdocs/11/iossns/Model/Core/Redis.php

我不知道如何解决问题。

你能帮忙吗?

谢谢!

你用的是什么PHP到Redis库?这是Redis的官方名单。您的网络服务器是什么?(Apache, nginx, etc)PHP 是如何运行的?(CGI,FPM,mod_php等)

这是 phpredis 中相同异常消息的线程。事实证明,phpredis目前不支持与php-fpm的持久连接。phpredis 的 2.2.3 版本有一些连接处理更改,可能会降低问题的频率。

我建议检查您的 Redis 连接器配置以...

  1. 禁用持久连接
  2. 启用连接重试
  3. 增加日志详细程度

你也可以考虑在 php.ini 中调整(通常增加)default_socket_timeout

这是一个 redis 6 错误。

您可以这样做:

sudo nano /etc/systemd/system/redis.service
# ADD THIS TO [Service] SECTION
ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"
sudo systemctl daemon-reload && sudo systemctl restart redis-server

在 Ubuntu 20.04 中,我发现 systemctl 正在尝试重新启动服务,因为它找不到/run/redis/redis-server.pidredis-server.service:失败,结果为"超时"。

Feb 25 17:51:09 artamredis systemd[1]: Failed to start Advanced key-value store.
Feb 25 17:51:09 artamredis systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 18.
Feb 25 17:51:09 artamredis systemd[1]: Stopped Advanced key-value store.
Feb 25 17:51:09 artamredis systemd[1]: Starting Advanced key-value store...
Feb 25 17:51:09 artamredis systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Operation not permitted

为了在/etc/redis/redis.conf 文件中解决它,请查找

pidfile /var/run/redis_6379.pid

并更改为

pidfile /run/redis/redis-server.pid