【问题标题】:PHP Redis Error: Uncaught exception ‘RedisException’PHP Redis 错误:未捕获的异常“RedisException”
【发布时间】:2012-04-22 11:24:13
【问题描述】:

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

它抛出:

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

我不知道如何解决这个问题。

你能帮忙吗?

谢谢!

【问题讨论】:

  • 检查 Redis 实例是否正在运行,您可以使用 redis-cli 连接(即不是来自 php)。
  • 你的代码在哪里??他们是你用来连接 Redis 的???

标签: php redis


【解决方案1】:

您使用的是什么 PHP-to-Redis 库? Here’s the official list from Redis。你的网络服务器是什么? (Apache、nginx 等)PHP 是如何运行的? (CGI、FPM、mod_php 等)

Here’s a thread for the same exception message in phpredis。事实证明 phpredis 目前不支持与 php-fpm 的持久连接。 phpredis 2.2.3 版对连接处理进行了一些更改,可能会降低问题的频率。

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

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

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

【讨论】:

    【解决方案2】:

    在 Ubuntu 20.04 中,我发现 systemctl 正在尝试重新启动服务,因为它找不到 /run/redis/redis-server.pid redis-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
    

    【讨论】:

      猜你喜欢
      • 2014-09-19
      • 1970-01-01
      • 2013-07-07
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      相关资源
      最近更新 更多