最近碰到在REDIS执行一步get操作的时候报出错误:Uncaught RedisException: read error on connection,感觉不可理解,REDIS连接没有发现问题,但是就是get失败,在redis的日志中也没有找到慢查询,说明这个报错也不是超时。连接没有发生问题,又没有超时,什么会读失败呢?

在网上找了些答案,但基本都是千遍一律地认为是这行配置的问题:

default_socket_timeout = 60;

都建议把它改成-1.不超时

ini_set('default_socket_timeout', -1);  //在php程序中修改
default_socket_timeout = -1; //或者修改配置文件

原因都写着:由于redis扩展也是基于php 的socket方式实现,因此该参数值同样会起作用。但想想如果是这个配置的问题的话,那意思就是说请求redis读时超时了是不是?可这个配置的单位是秒啊!你能超60秒?如果一个请求超过了60秒还没有执行成功,这个值改大了又有什么意思?不知道网上碰到这个问题并写着按这个方法解决的朋友是不是后面再也没有碰到这个问题。
但我就是怀疑是这个地方的问题!
    在网上找了些相关的资料,也翻墙出去看了一些。看到了这么一篇讨论,里面有一个回答:
http://stackoverflow.com/questions/18072407/php-redis-timeout-read-error-on-connection

After
a lot of study of articles and doing my own strace's of redis and php,
it seemed the issue was easily fixed by this solution. The main issue in
my use case was that redis server is not able to fork a process towards
saving the in-memory writes to the on-disk db.
    I have left all
the timeout values in php.ini and redis.conf as they were without making
the hacky changes suggested and then tried the above solution alone,
and this issue 'read error on connection' that was unfixable using all
the suggestions around changing timeout values across php and redis conf
files went away.
    I also saw some suggestions around increasing
limit on file descriptors to 100000 etc. I am running my use case on a
cloud server with file descriptor limit at 1024 and my use case runs
even with that limit perfectly.

其中提到的 by this solution 链接到了这篇文章的这个位置:从上面的说法来看这个是可以解决这个问题,我还没有测试验证。文章链接

https://groups.google.com/forum/#!msg/redis-db/3Eh2hhsXQ1g/_nAzuK--nYYJ  提到的解决方法如下:

> Ok further investigations showed that probably this is due to 
> /proc/sys/vm/overcommit_memory 
> If it's zero in your system try to set it to 1 or 2 and check what 
> happens. I'm going to try this in few hours.

echo 1 > /proc/sys/vm/overcommit_memory

works perfectly! So the problem was with the kernel _estimating_ how 
much memory would the forked process need. Echoing "1" as I understand 
disables the check and enables the process to fork.

Since "0" is default of overcommit_memory, perhaps the issue is much 
more common on Linux boxes. It also looks like MacOSX is free of this 
issue.

If confirmed, it would be nice to have it added to the FAQ. 
Great job and many thanks again

----------------------------------------------------------------

关于内核参数overcommit_memory的值的意义:                                    
overcommit_memory文件指定了内核针对内存分配的策略,其值可以是0、1、2。                               
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。 
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

修改方法:
/etc/sysctl.conf                                                        
vm.overcommit_memory=1
或者
sysctl vm.overcommit_memory=1
或者
echo 1 > /proc/sys/vm/overcommit_memory

本文地址:http://www.04007.cn/article/376.html 未经许可,不得转载. 手机访问本页请扫描下方二维码:

在使用redis的时候,出现了Error: read error on connection.
找了一下相关资料,在官方也有很多人提出这个问题
phpredis的作者的意思是,是因为default_socket_timeout的问题,将它设为0就好了.
但很多人都说设为0,在60秒后还是会挂 ,只有设为-1才OK
于是,在命令行下subscribe的时候,先init_set('default_socket_timeout',-1);
问题解决 .

http://www.neatstudio.com/show-2357-1.shtml

关于redis的问题:RedisException with message read error on connection的更多相关文章

  1. [PHP][REDIS]phpredis 'RedisException' with message 'read error on connection'

    最近一个后台常驻job通过redis的brpop阻塞读取消息时,设置了永不超时 while( $re=$redis->brPop($queue_name,0) ){ } 但是在实际的使用中发现很 ...

  2. windows redis:Uncaught exception 'RedisException' with message 'Redis server went away'

    window-exe-redis-2.8.12服务,当你复制好php_igbinary.dll,php_redis.dll时候,你运行redis报错:Fatal error: Uncaught exc ...

  3. idhttp post 出现exception class EIdSocketError with message 'Socket Error # 10054的解决办法(捕捉异常,防止程序挂掉)

    由于项目需要.需要向一个地址提交数据.提交的次数很频繁,但是程序经常raised exception class EIdSocketError with message 'Socket Error # ...

  4. redis :read error on connection

    最近做了一个多人竞拍的小功能  因为以前没做过 所以踩了很多坑用的是 mysql + php + redis 实现的竞拍功能 这里先说一下踩得第二个坑redis  的原因  真是欲哭无泪  解决完一个 ...

  5. PHP程序连接Redis报read error on connection问题

    线上PHP程序动不动就报PHP Fatal error: Uncaught RedisException: read error on connection错误,就是连接Redis在那么1秒钟有问题, ...

  6. nova instance出错:"message": "Proxy error: 502 Read from server failed

    执行 $ nova resize instance1 时候出错: {, "details": " File \"/opt/stack/nova/nova/com ...

  7. 解决webApi<Message>An error has occurred.</Message>不能写多个Get方法的问题

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷.     本人最近在研究C#webAPI相关知识,发现webAPI不能够支持 ...

  8. selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary

    使用Chrome浏览器时,经常会遇到以下报错:浏览器没有调用起来 selenium.common.exceptions.WebDriverException: Message: unknown Err ...

  9. Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing 'value'

    Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing ' ...

随机推荐

  1. 2018-2-13-visual-Studio-无法调试,提示程序跟踪已退出

    title author date CreateTime categories visual Studio 无法调试,提示程序跟踪已退出 lindexi 2018-2-13 17:23:3 +0800 ...

  2. 用Python的requests库作接口测试——对响应进行迭代

    使用 requests.Response.iter_lines() 方法,可以很方便地对流式API(例如 Twitter的流式API )的响应进行迭代. 简单地设置 stream 为 True 便可以 ...

  3. linux下文件操作之cp和mv

    Linux CP文件夹略过目录的解决 root@QGY:/home/qgy# cp image/newimage_raw /mnt/4T/qin/cp: 略过目录'image/newimage_raw ...

  4. [Array]414. Third Maximum Number

    Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...

  5. 配置android studio环境2

    安装android studio 2.1运行 exe 程序 安装截图 备注 :O(∩_∩)O~等了 ,但是还是失败, 完全安装啊,不影响,可以手动运行安装目录下的 如:D:\Program Files ...

  6. 【python之路28】模块python与excel

    一.可使用的第三方库 python中处理excel表格,常用的库有xlrd(读excel)表.xlwt(写excel)表.openpyxl(可读写excel表)等.xlrd读数据较大的excel表时效 ...

  7. python 显示彩色文本

    实现过程:      终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关.      转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示是27,用 ...

  8. SPSS20.O---软件安装

    统计要与大量的数据打交道,涉及繁杂的计算和图表绘制.现代的数据分析工作如果离开统计软件几乎是无法正常开展.在准确理解和掌握了各种统计方法原理之后,再来掌握几种统计分析软件的实际操作,是十分必要的. 常 ...

  9. python 类属性、静态方法与类方法

    1. 类属性 1.1 定义 在类中方法外通过属性名 = 属性值定义的属性 访问方式: 类名.属性名 对象名.属性名 class Student: cls_id = 102 stu = Student( ...

  10. vue-cli3 搭建的前端项目基础模板

    基于 vue-cli3 搭建的前端模板,fork 或 clone 本仓库,即可搭建完成一个新项目的基础模板,源码地址,欢迎 star 或 fork 特性 CSS 预编译语言:less Ajax: ax ...