当前位置:网站首页>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
边栏推荐
- Secrets in buffctf file 1
- Kettle experiment conversion case
- Kettle实验 (三)
- Trc20 fund collection solution based on thinkphp5 version
- 三、6【Verilog HDL】基础知识之门级建模
- node安装
- Leetcode question bank 78 Subset (recursive C implementation)
- GUI, CLI and UNIX Philosophy
- Leetcode-199 - right view of binary tree
- JS what is an event? Event three elements and operation elements
猜你喜欢

Redis 异常 read error on connection 解决方案

PHP笔记(一):开发环境配置

Pre parsing of JS

Go language learning notes - slice, map | go language from scratch

AQS & reentrantlock implementation principle

How to protect open source projects from supply chain attacks - Security Design (1)

501. 二叉搜索树中的众数

653. Sum of two IV - input BST

Node installation

node安装
随机推荐
108. 将有序数组转换为二叉搜索树
Redis 异常 read error on connection 解决方案
Kernel PWN learning (3) -- ret2user & kernel ROP & qwb2018 core
What is monitoring intelligent playback and how to use intelligent playback to query video recording
Write down the post order traversal of the ~ binary tree
[C language] document operation
How to protect open source projects from supply chain attacks - Security Design (1)
Your guide to lowering your cholesterol with TLC (continuously updated)
重载、重写、隐藏的对比
Alibaba cloud architects interpret the four mainstream game architectures
Go language learning notes - array | go language from scratch
MySQL of database -- Fundamentals
112. 路径总和
Go language learning notes - slice, map | go language from scratch
Leetcode0587. Install fence
web页面如何渲染
Leetcode question bank 78 Subset (recursive C implementation)
Two declaration methods of functions of JS
Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
ATSS(CVPR2020)