Predis 给出“从服务器读取行时出错" [英] Predis is giving 'Error while reading line from server'
问题描述
我正在使用 predis 并且它订阅了一个频道并在听,它抛出错误并死了,如下所示,大约 60 秒后,它肯定不是我的 Web 服务器错误或其超时.
I am using predis and 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.
此处正在讨论类似的问题.不能得到太多.
There is a similar issue being discussed here. Could not get much of it.
我尝试将 predis conf 文件中的 connection_timeout 设置为 0,但没有太大帮助.
I tried setting connection_timeout in predis conf file to 0, but doesn't helps much.
此外,如果我继续使用(向其发送数据并处理)工作人员,它也不会出现任何错误.所以它可能是某个地方的超时,这也与连接有关.
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
}
跟踪
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
也检查了 redis.conf 超时,它也被禁用了.
Checked the redis.conf timeout too, its also disabled.
推荐答案
只需将 read_write_timeout
连接参数设置为 0 或 -1 即可解决此问题.例如
Just set the read_write_timeout
connection parameter to 0 or -1 to fix this. e.g.
$redis = new Predis\Client('tcp://10.0.0.1:6379'."?read_write_timeout=0");
设置连接参数在自述文件中记录.Redis 的作者在 an issue 中指出了 read_write_timeout
参数与此错误的相关性在 GitHub 上,他指出:
Setting connection parameters is documented in the README. The author of Redis noted the relevance of the read_write_timeout
parameter to this error in an issue on GitHub, in which he notes that:
如果您在类似守护进程的脚本中使用 Predis,如果您想完全禁用超时,您应该将 read_write_timeout
设置为 -1
(此值适用于较旧的和较新版本的 Predis).另外,请记住,您必须通过在 redis.conf 或 Redis 将在 300 秒不活动后断开空闲客户端的连接.
If you are using Predis in a daemon-like script you should set
read_write_timeout
to-1
if 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 = 0
in redis.conf or Redis will drop the connection of idle clients after 300 seconds of inactivity.
这篇关于Predis 给出“从服务器读取行时出错"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!