Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

qasimalbaqali's avatar

Queue with predis: Error while reading line from the server.

I have setup my server using Forge. I have 2 cron jobs, one that runs nightly and the other that runs every 5 minutes. The server specification that I have are:

  • 2GB RAM
  • 2 vCPUs

The application that I am building checks for idle reservations every 5 minutes, and deletes them. I am using redis as the queue set up. Redis is set up by default in forge, so I created a queue worker through the forge panel with the following config:

  • connection: redis
  • queue: default
  • timeout: 30
  • processes: 2
  • tries: any
  • daemon: yes

The error starts whenever I fire of a Notification that send an email as well as an SMS. The emails are always sent fine, even after the error appears in the logs, but the SMS part (NEXMO) never get delivered. And every 2-3 minutes the following error gets logged:

local.ERROR: Error while reading line from the server. [tcp://127.0.0.1:6379] {"exception":"[object] (Predis\Connection\ConnectionException(code: 0): Error while reading line from the server. [tcp://127.0.0.1:6379] at /home/forge/alpha.rawag.me/vendor/predis/predis/src/Connection/AbstractConnection.php:155) [stacktrace]

Anyone has any idea? I read around and people suggested to change read_write_timeout to 0 in the config/database.php but didn't solve my problem. Any ideas what it might be?

0 likes
3 replies
click's avatar

Not a direct solution I think. But did you restart your queue worker when you made the change to read_write_timeout?

And mayb as a tip you could try https://horizon.laravel.com a free package that helps you monitor and visualize the state of your redis queue. And pretty easy setup.

carltondickson's avatar

Getting similar issues on Heroku when running multiple dynos. Seems to error immediately after I dispatch a job to the queue or a few minutes after a job tries to process.

I added the following code to log more information on these errors.

# \App\Exceptions\Handler::report

        if ($exception instanceof CommunicationException) {
            $stream = $exception->getConnection()->getResource();
            $errorMessage = var_export(stream_get_meta_data($stream), true);
            \Log::error("Redis connection exception", [
                'metadata' => $errorMessage
            ]);
        }

This looks like I'm blocked while trying to connect to read/write

  "metadata": {
    "timed_out": false,
    "blocked": true,
    "eof": false,
    "stream_type": "tcp_socket/ssl",
    "mode": "r+",
    "unread_bytes": 0,
    "seekable": false
  }
}

I have a ticket here - https://github.com/nrk/predis/issues/507

qasimalbaqali's avatar

@click Thanks for your reply. I saw this solution in couple of threads around the internet but didn't help. @carltondickson Thank you for your reply. I added horizon to my app to have a better look at the queues and jobs. At least for now they are all running properly, but the error in my log is still being printed by the 3 workers every minute.

Here is a stack trace if it would help anyone

[2018-06-02 02:53:03] local.ERROR: Error while reading line from the server. [tcp://127.0.0.1:6379] {"exception":"[object] (Predis\Connection\ConnectionException(code: 0): Error while reading line from the server. [tcp://127.0.0.1:6379] at /home/forge/qasim.me/vendor/predis/predis/src/Connection/AbstractConnection.php:155)
[stacktrace]
#0 /home/forge/qasim.me/vendor/predis/predis/src/Connection/StreamConnection.php(314): Predis\Connection\AbstractConnection->onConnectionError('Error while rea...')
#1 /home/forge/qasim.me/vendor/predis/predis/src/Connection/AbstractConnection.php(120): Predis\Connection\StreamConnection->read()
#2 /home/forge/qasim.me/vendor/predis/predis/src/Connection/AbstractConnection.php(112): Predis\Connection\AbstractConnection->readResponse(Object(Predis\Command\ServerEval))
#3 /home/forge/qasim.me/vendor/predis/predis/src/Client.php(331): Predis\Connection\AbstractConnection->executeCommand(Object(Predis\Command\ServerEval))
#4 /home/forge/qasim.me/vendor/predis/predis/src/Client.php(314): Predis\Client->executeCommand(Object(Predis\Command\ServerEval))
#5 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(96): Predis\Client->__call('eval', Array)
#6 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(108): Illuminate\Redis\Connections\Connection->command('eval', Array)
#7 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php(191): Illuminate\Redis\Connections\Connection->__call('eval', Array)
#8 /home/forge/qasim.me/vendor/laravel/horizon/src/RedisQueue.php(108): Illuminate\Queue\RedisQueue->migrateExpiredJobs('queues:default:...', 'queues:default')
#9 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php(174): Laravel\Horizon\RedisQueue->migrateExpiredJobs('queues:default:...', 'queues:default')
#10 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php(154): Illuminate\Queue\RedisQueue->migrate('queues:default')
#11 /home/forge/qasim.me/vendor/laravel/horizon/src/RedisQueue.php(92): Illuminate\Queue\RedisQueue->pop('default')
#12 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(244): Laravel\Horizon\RedisQueue->pop('default')
#13 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(105): Illuminate\Queue\Worker->getNextJob(Object(Laravel\Horizon\RedisQueue), 'default')
#14 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#15 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#16 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#17 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#18 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#19 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#20 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#21 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#22 /home/forge/qasim.me/vendor/symfony/console/Command/Command.php(251): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#23 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#24 /home/forge/qasim.me/vendor/symfony/console/Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /home/forge/qasim.me/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/forge/qasim.me/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /home/forge/qasim.me/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /home/forge/qasim.me/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 {main}
"} 

Please or to participate in this conversation.