Predis is giving 'Error while reading line from server'

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");

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:

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 setting timeout = 0 in redis.conf or Redis will drop the connection of idle clients after 300 seconds of inactivity.


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).


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.

Tags:

Php

Redis