php Predis 给出“从服务器读取行时出错”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11776029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Predis is giving 'Error while reading line from server'
提问by amitchhajer
I am using predisand its subscribed to a channel and listening, it throws the error and die , shown below, after 60 secs exaxtly, its surely not my web server error or its timeout.
我正在使用predis并且它订阅了一个频道并在收听,它抛出错误并死亡,如下所示,在 60 秒之后,它肯定不是我的网络服务器错误或超时。
There is a similar issue being discussed here. Could not get much of it.
目前正在讨论的一个类似的问题在这里。不能得到很多。
I tried setting connection_timeout in predis conf file to 0, but doesn't helps much.
我尝试将 predis conf 文件中的 connection_timeout 设置为 0,但没有太大帮助。
Also if i keep using (send data to it and it processes) the worker it doesn't give any error. So its likely a timeout somewhere, and that too in connection.
此外,如果我继续使用(向其发送数据并处理)工作人员,它不会给出任何错误。所以它可能是某个地方的超时,这也与连接有关。
Here is my code snippet, which is likely producing error, because if data is given to worker it runs this code and go forward, which produces no error after that.
这是我的代码片段,它可能会产生错误,因为如果将数据提供给工作人员,它会运行此代码并继续前进,之后不会产生任何错误。
$pubsub = $redis->pubSub();
$pubsub->subscribe($channel1);
foreach ($pubsub as $message) { //doing stuff here and unsubscribing from channel
}
Trace
痕迹
PHP Fatal error: Uncaught exception 'Predis\Network\ConnectionException' with message 'Error while reading line from the server' in Predis/Network/ConnectionBase.php:159 Stack trace:
#0 library/vendor/predis/lib/Predis/Network/StreamConnection.php(195): Predis\Network\ConnectionBase->onConnectionError('Error while rea...')
#1 library/vendor/predis/lib/Predis/PubSub/PubSubContext.php(259): Predis\Network\StreamConnection->read()
#2 library/vendor/predis/lib/Predis/PubSub/PubSubContext.php(206): Predis\PubSub\PubSubContext->getValue()
#3 pdf/file.php(16): Predis\PubSub\PubSubContext->current()
#4 {main} thrown in Predis/Network/ConnectionBase.php on line 159
Checked the redis.conf timeout too, its also disabled.
也检查了 redis.conf 超时,它也被禁用了。
回答by amitchhajer
Just set the read_write_timeoutconnection parameter to 0 or -1 to fix this. e.g.
只需将read_write_timeout连接参数设置为 0 或 -1 即可解决此问题。例如
$redis = new Predis\Client('tcp://10.0.0.1:6379'."?read_write_timeout=0");
Setting connection parameters is documented in the README. The author of Redis noted the relevance of the read_write_timeoutparameter to this error in an issue on GitHub, in which he notes that:
README 中记录了设置连接参数。Redis 的作者在 GitHub 上的一个问题中指出了该read_write_timeout参数与此错误的相关性,他在其中指出:
If you are using Predis in a daemon-like script you should set
read_write_timeoutto-1if you want to completely disable the timeout (this value works with older and newer versions of Predis). Also, remember that you must disable the default timeout of Redis by settingtimeout = 0in redis.confor Redis will drop the connection of idle clients after 300 seconds of inactivity.
如果您在类似守护进程的脚本中使用 Predis,您应该设置
read_write_timeout为-1是否要完全禁用超时(此值适用于较旧和较新版本的 Predis)。另外,请记住,您必须通过timeout = 0在redis.conf 中设置来禁用 Redis 的默认超时,否则 Redis 将在 300 秒不活动后断开空闲客户端的连接。
回答by Jayesh Pawar
I had similar problem, better solution to the situation is not setting the timeout to 0 but using a exponential backoff and set the upper and the lower limit. Change in the config parameter connection_timeout to 0 will also solve the issue.
我有类似的问题,更好的解决方案不是将超时设置为 0,而是使用指数退避并设置上限和下限。将配置参数 connection_timeout 更改为 0 也将解决该问题。
回答by Romil Goel
I got the resolution to the problem. So, there is a limit to ports that a application server can connect to a particular application on another machine. These ports were getting exhausted. We increased the limit and the problem got resolved.
我得到了问题的解决方案。因此,应用程序服务器可以连接到另一台机器上的特定应用程序的端口是有限制的。这些端口已经耗尽。我们增加了限制,问题得到了解决。
How we got to know about this problem ? In php, we were getting "Cannot assign requested address" error while creating a socket (error code 99).
我们是如何知道这个问题的?在 php 中,我们在创建套接字时收到“无法分配请求的地址”错误(错误代码 99)。

