predis: Error while reading line from the server
CommunicationException
s are thrown with the message ‘Error while reading line from the server’ from time to time. The Predis part of an example stack trace:
Message: Error while reading line from the server
Thrown at: /var/www/lib/redis/Predis.php:1568
Trace:
#0 /var/www/lib/redis/Predis.php(1636): Predis\Connection->onCommunicationException('Error while rea...')
#1 /var/www/lib/redis/Predis.php(724): Predis\Connection->readLine()
#2 /var/www/lib/redis/Predis.php(1577): Predis\FastResponseReader->read(Object(Predis\Connection))
#3 /var/www/lib/redis/Predis.php(1586): Predis\Connection->readResponse(Object(Predis\Commands\Auth))
#4 /var/www/lib/redis/Predis.php(225): Predis\Connection->executeCommand(Object(Predis\Commands\Auth))
#5 /var/www/lib/redis/RedisProxy.php(21): Predis\Client->__call('auth', Array)
#6 /var/www/lib/redis/RedisProxy.php(21): Predis\Client->auth('password')
We couldn’t find anything in common in the affected scripts. Some errors are from a local Redis server, some from a remote one. An example that sometimes generates this error:
The script is run by Apache, browsers call it directly by URL, so there can be a lot of instances running at once. The following Redis commands are run via Predis (in this order; a
, b
, c
and d
are different tables):
- AUTH
- SELECT a
- EXISTS
- (if a condition is met) SETEX
- SELECT b
- RPUSH
- if a condition is met
- SELECT b
- INCR
- SELECT c
- GET
- SELECT d
- RPUSH
The bold commands are those that have ever generated the error. The majority (99%) is on AUTH.
Environment:
$ redis-server -v
Redis server version 2.2.4 (00000000:0)
Predis version 0.6.6
$ php -v
PHP 5.3.3-0.dotdeb.1 with Suhosin-Patch (cli) (built: Oct 1 2010 08:49:29)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
$ /usr/sbin/apache2ctl -v
Server version: Apache/2.2.9 (Debian)
Server built: Apr 20 2010 15:40:17
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 28 (8 by maintainers)
In my case configuring Redis was not enough setting
default_socket_timeout=-1
in php.ini makes it work. thanks @bencromwell.Apologies, I deleted my comment as I wasn’t sure the issue was the same after more debugging.
It might be though.
I swapped out Predis for phpredis and experienced the same error. After more searching I found the setting
default_socket_timeout
and set it to -1. This is in php.inihttp://php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout
That did the trick. It seems that is necessary despite setting the connection parameter read_write_timeout. PHP’s setting trumps it, both are required by the looks of things.
On 30 November 2016 at 11:43, Pravin Dahal notifications@github.com wrote:
This is how I managed to capture the debug info:
I get the following:
I have set read_write_timeout to -1, timeout in redis.conf to 0, second param to blpop as 0. Has anyone managed to find out more about this?
More info: Using redis 3 (docker image, alpine variant) with Laravel 5.1 in a long running artisan command.
The cause of the issue was a faulty Realtek driver (r8169 before kernel 2.6.30 is buggy, have to use r8168). Nothing to do with Redis or Predis.