当前位置:网站首页>Redis exception read error on connection solution
Redis exception read error on connection solution
2022-04-23 09:32:00 【Notes of Pan Guangyu de Xiaobai】
One 、 Cause and scene :
In the interface connection redis when , Used pconnect Conduct redis A long connection , stay Redis->auth() Exception thrown in :
PHP Fatal error: Uncaught exception 'RedisException' with message 'read error on connection'
notes : because php-fpm Reusability of connections , therefore , When it exists cgi Process Manager [ Such as php-fpm,spawn-cgi], Use pconnect Efficient than connect high . But because each persistent connection takes up memory , When there is a large amount of concurrency , It is likely to cause memory shortage
Two 、 Reasons for appearance
adopt pconnect Of redis Long connections are not actively released , Will always be Stay in php-fpm In progress , Waiting to complete the next requested task , Even if passed close Only to make the current php No more redis request , But it can't really close redis A long connection , Connections will still be reused in subsequent requests , until fpm End of process life cycle .
In this way, the following two situations will occur :
1) reason 1 Using a disconnected connection
If this connection is broken , The next request may directly use the last disconnected connection , When php-fpm Process the next request reuse A disconnected connection may cause read error on connection It's abnormal , Here are phpredis Explanation of the source code :
2) reason 2: Execution timeout
a) The timeout set by the client is too short ;
b) The client did not set the timeout , But the execution time of the server exceeds the default timeout setting
php There is a configuration item default_socket_timeout It means a socket Connection timeout , The default is 60s, and phpredis The underlying connection of this extension redis It is used. socket, So when a connection is in 60 When not used within seconds , The next connection will throw this exception .
3、 ... and 、 Solution
1) If it's the reason 1:
Change long connection to short connection perhaps stay pconnect Add timeout in
$this->redis->pconnect($host, $port, 2); //@todo 2 The connection timed out after seconds , A new long connection will be used
2) If it's the reason 2: Modify timeout
( Not recommended ) programme 1:
php.ini Set in
default_socket_timeout = -1
And then restart php-fpm
programme 2:
Dynamic modification php.ini
ini_set('default_socket_timeout', -1); // No timeout
programme 3:
Set up redis The timeout time of is no timeout :
$this->redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
Reference resources :
read error on connection Analysis of two reasons for - SegmentFault Think no
版权声明
本文为[Notes of Pan Guangyu de Xiaobai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230929494156.html
边栏推荐
- kernel-pwn学习(4)--Double Fetch&&0CTF2018-baby
- Codeforces Round #784 (Div. 4)
- 108. Convert an ordered array into a binary search tree
- Go language learning notes - structure | go language from scratch
- Summary of wrong questions 1
- Two declaration methods of functions of JS
- JS prototype chain
- Leetcode-199 - right view of binary tree
- Kettle实验
- OpenCV中的图像处理 —— 轮廓入门+轮廓特征
猜你喜欢
Dropout技术之随机神经元与随机深度
小程序报错:Cannot read property 'currentTarget' of undefined
kettle实验
Personal homepage software fenrus
What is monitoring intelligent playback and how to use intelligent playback to query video recording
ATSS(CVPR2020)
错题汇总1
Leetcode-199 - right view of binary tree
亚马逊云科技入门资源中心,从0到1轻松上云
LeetCode 1611. The minimum number of operations to make an integer 0
随机推荐
JS scope, scope chain, global variables and local variables
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
JS node operation, why learn node operation
SAP 101K 411K 库存变化
How to render web pages
JS DOM learn three ways to create elements
Secrets in buffctf file 1
阿里云架构师解读四大主流游戏架构
MySQL of database -- Fundamentals
GUI, CLI and UNIX Philosophy
Leetcode0587. 安装栅栏(difficult)
Dropout技术之随机神经元与随机深度
npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
Canary publishing using ingress
错题汇总1
Employee probation application (Luzhou Laojiao)
How to obtain geographical location based on photos and how to prevent photos from leaking geographical location
112. 路径总和
Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
Give the method of instantiating the object to the new object