当前位置:网站首页>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
边栏推荐
猜你喜欢
Flink SQL realizes the integration of stream and batch
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
Redis 异常 read error on connection 解决方案
Leetcode question bank 78 Subset (recursive C implementation)
653. Sum of two IV - input BST
Kettle experiment conversion case
501. 二叉搜索树中的众数
亚马逊云科技入门资源中心,从0到1轻松上云
小程序报错:Cannot read property 'currentTarget' of undefined
nn. Explanation of module class
随机推荐
EmuElec 编译总结
Principle of synchronized implementation
kettle实验
Using sqlmap injection to obtain the account and password of the website administrator
Summary of common concepts and problems of linear algebra in postgraduate entrance examination
How to render web pages
kettle庖丁解牛第14篇之JSON输入
npm ERR! network
Kernel PWN learning (4) -- double fetch & 0ctf2018 baby
Kettle实验
JS what is an event? Event three elements and operation elements
Kettle experiment (III)
Thread scheduling (priority)
Codeforces Round #784 (Div. 4)
机器学习(六)——贝叶斯分类器
Pre parsing of JS
员工试用期转正申请书(泸州老窖)
重载、重写、隐藏的对比
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
MySQL of database -- basic common query commands