当前位置:网站首页>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
边栏推荐
- Redis 异常 read error on connection 解决方案
- Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
- MySQL of database -- overview and installation
- Chapter VIII project stakeholder management of information system project manager summary
- Creation of raid0 and RAID5 and Simulation of how RAID5 works
- Kettle experiment
- Summary of common concepts and problems of linear algebra in postgraduate entrance examination
- Leetcode question bank 78 Subset (recursive C implementation)
- Simple understanding of arguments in JS
- High paid programmer & interview question series 91 limit 20000 loading is very slow. How to solve it? How to locate slow SQL?
猜你喜欢

Detailed explanation of delete, truncate and drop principles in MySQL database

【SQL server速成之路】数据库的视图和游标

JS what is an event? Event three elements and operation elements

Exclusive thoughts and cases of JS

小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab

NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’

Go language learning notes - exception handling | go language from scratch

Applet error: cannot read property'currenttarget'of undefined

Redis 异常 read error on connection 解决方案

Redis 内存占满导致的 Setnx 命令执行失败
随机推荐
Emuelec compilation summary
成功的DevOps Leader 应该清楚的3个挑战
501. Mode in binary search tree
Colorui solves the problem of blocking content in bottom navigation
MySQL of database -- Fundamentals
Your guide to lowering your cholesterol with TLC (continuously updated)
Trc20 fund collection solution based on thinkphp5 version
SQL used query statements
Redis 异常 read error on connection 解决方案
Three challenges that a successful Devops leader should be aware of
Go language learning notes - exception handling | go language from scratch
重载、重写、隐藏的对比
JS node operation, why learn node operation
node安装
Go language learning notes - array | go language from scratch
机器学习(六)——贝叶斯分类器
Kettle实验 转换案例
Flutter's loading animation is more interesting
Machine learning (VI) -- Bayesian classifier
108. 将有序数组转换为二叉搜索树