PHP Redis timeout, read error on connection?

php, phpredis, redis

Solution

The current solution I know of is to disable persistent connections for phpredis, as they have been reported as buggy since October 2011. If you’re using php-fpm or other threaded models, the library specifically disables persistent connections.

Reducing the frequency of this error might be possible by adjusting the php.ini `default_socket_timeout` value.

Additionally, read timeout configurations in phpredis are not universally supported. The feature (look for `OPT_READ_TIMEOUT`) was introduced in tag 2.2.3.

Problem

"PHP Fatal error: Uncaught exception 'RedisException' with message 'read error on connection'" The driver here is phpredis ``` $redis->blpop('a', 0); ``` This always times out after ~1 minute. My redis.conf says timeout 0 and `$redis->getOption(Redis::OPT_READ_TIMEOUT)` returns `double(0)` If I do this it has never timed out `$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);` Why do I need -1? Redis documentation says `timeout 0` in redis.conf should never time me out. "By default recent versions of Redis don't close the connection with the client if the client is idle for many seconds: the connection will remain open forever."

Original source