关于redis的问题:RedisException with message read error on connection
最近碰到在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的更多相关文章
- [PHP][REDIS]phpredis 'RedisException' with message 'read error on connection'
最近一个后台常驻job通过redis的brpop阻塞读取消息时,设置了永不超时 while( $re=$redis->brPop($queue_name,0) ){ } 但是在实际的使用中发现很 ...
- 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 ...
- idhttp post 出现exception class EIdSocketError with message 'Socket Error # 10054的解决办法(捕捉异常,防止程序挂掉)
由于项目需要.需要向一个地址提交数据.提交的次数很频繁,但是程序经常raised exception class EIdSocketError with message 'Socket Error # ...
- redis :read error on connection
最近做了一个多人竞拍的小功能 因为以前没做过 所以踩了很多坑用的是 mysql + php + redis 实现的竞拍功能 这里先说一下踩得第二个坑redis 的原因 真是欲哭无泪 解决完一个 ...
- PHP程序连接Redis报read error on connection问题
线上PHP程序动不动就报PHP Fatal error: Uncaught RedisException: read error on connection错误,就是连接Redis在那么1秒钟有问题, ...
- nova instance出错:"message": "Proxy error: 502 Read from server failed
执行 $ nova resize instance1 时候出错: {, "details": " File \"/opt/stack/nova/nova/com ...
- 解决webApi<Message>An error has occurred.</Message>不能写多个Get方法的问题
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷. 本人最近在研究C#webAPI相关知识,发现webAPI不能够支持 ...
- selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary
使用Chrome浏览器时,经常会遇到以下报错:浏览器没有调用起来 selenium.common.exceptions.WebDriverException: Message: unknown Err ...
- Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing 'value'
Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing ' ...
随机推荐
- 有趣的纯CSS实现动态晴阴雨雪
我们先来看看实现的效果吧 非常的美腻,对吧.这个是纯css,且单标签实现的哦~ 先贴完整代码,我们再来看看这个里面究竟有什么可以借鉴的知识点 <!DOCTYPE html> <htm ...
- vue 图片上传功能
这次做了vue页面的图片上传功能,不带裁剪功能的! 首先是html代码,在input框上添加change事件,如下: <ul class="clearfix"> ...
- spring源码学习之bean的加载(三)
接着二中的继续写,那个都超过1000行了,哈,需要重新写一个,要不太长了,我都看不下去了 7.4 初始化bean doCreateBean函数中有这样一行代码:这行代码中initializeBean函 ...
- css3 实现明信片正背面翻转
<!DOCTYPE html> <html lang="zh-cn" style="width: 100%;height: 100%;"> ...
- Java方法传参的问题
1.基本数据类型(byte,short,int,long,float,double,boolean,char)的值传递,不改变其值 2.引用数据类型的值传递,改变其值 3.String类型虽然是引用数 ...
- 2019.8.3 NOIP模拟测试12 反思总结【P3938 斐波那契,P3939 数颜色,P3940 分组】
[题解在下面] 早上5:50,Gekoo同学来到机房并表态:“打暴力,打暴力就对了,打出来我就赢了.” 我:深以为然. (这是个伏笔) 据说hzoi的人还差两次考试[现在是一次了]就要重新分配机房,不 ...
- ES6中async和await说明和用法
昨天看了一篇vue的教程,作者用async/ await来发送异步请求,从服务端获取数据,代码很简洁,同时async/await 已经被标准化,是时候学习一下了. 先说一下async的用法,它作为一个 ...
- 用 Python 写一个 NoSQL 数据库Python
NoSQL 这个词在近些年正变得随处可见. 但是到底 “NoSQL” 指的是什么? 它是如何并且为什么这么有用? 在本文, 我们将会通过纯 Python (我比较喜欢叫它, “轻结构化的伪代码”) 写 ...
- CSS制作的32种图形效果[梯形|三角|椭圆|平行四边形|菱形|四分之一圆|旗帜]
转载链接:http://www.w3cplus.com/css/css-simple-shapes-cheat-sheet 前面在<纯CSS制作的图形效果>一文中介绍了十六种CSS画各种不 ...
- webpack学习之——Entry Points(入口起点)
1.Entry property(entry属性) 1.1 Single Entry (Shorthand) Syntax(单个入口语法) 用法:entry: string | Array<st ...