laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.87k stars 657 forks source link

Laravel Redis: Error while writing bytes to the server. #318

Closed andriihorpenko closed 6 years ago

andriihorpenko commented 6 years ago

I am experiencing some errors while interacting with Redis in Laravel. Every time I call Redis functions (e.x. zrange), Laravel logs this error [2018-04-07 20:02:46] local.ERROR: Error while writing bytes to the server. [tcp://127.0.0.1:6379] {"exception":"[object] (Predis\\Connection\\ConnectionException(code: 0): Error while writing bytes to the server. [tcp://127.0.0.1:6379] at /var/www/html/vendor/predis/predis/src/Connection/AbstractConnection.php:155) I can't fix this. Help me.. P.S. Everything is up-to-date(I mean laravel, horizon and redis).

mfn commented 6 years ago

Seems to be a pure connectivity problem? Problem connection to redis? Is redis on the same or remote (Timeout to redis)?

andriihorpenko commented 6 years ago

I haven't experienced any problems with connection(while using redis-cli?). Redis is on the same server and running along with my site.

drbyte commented 6 years ago

Is Redis running out of memory or available connections?

https://github.com/laravel/horizon/issues/152#issuecomment-331877396 https://github.com/nrk/predis/issues/33

andriihorpenko commented 6 years ago

By the way, my server has 128 gigs of RAM. How can I measure Redis memory consumption? Setting maxmemory to 0?

andriihorpenko commented 6 years ago

Max memory is default and set to 0.

emielmolenaar commented 6 years ago

Always set maxmemory to a defined limit to make sure you get some errors reported instead of some silent fails. See Check out https://redis.io/topics/admin .

Also, I suggest you use phpredis (https://github.com/phpredis/phpredis) instead of predis. This should result in a better performing app since phpredis is a PHP extension and predis is native PHP. If you're on Ubuntu or Debian, I can recommend Ondrej Sury's repository for that: https://deb.sury.org/ .

francislavoie commented 6 years ago

@emielmolenaar even better, use phpiredis (note the i) which is an extension that predis supports as a backend. Can be turned on by adding the following to database.php config under redis

        'options' => [
            'connections' => [
                'tcp'  => 'Predis\Connection\PhpiredisStreamConnection',
                'unix' => 'Predis\Connection\PhpiredisSocketConnection',
            ],
        ],
emielmolenaar commented 6 years ago

Thanks @francislavoie ! Will check it out.

romilgoel commented 6 years ago

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

andriihorpenko commented 6 years ago

How and where do we have to change that limit? Thanks in advance!

andriihorpenko commented 6 years ago

Old stuff, closing.

swierczek commented 2 years ago

Leaving a breadcrumb here: $client->hgetall($uri); was failing in PHP with the caught exception "Error while writing bytes to the server." But logging into redis directly and running HGETALL <path> returned the expected result, and that somehow kicked PHP into gear to work.

fwilliamconceicao commented 1 year ago

I'm here using PHP 8.2 and Laravel 10 and this issue still persist :(

menadio commented 7 months ago

I'm here using PHP 8.2 and Laravel 10 and this issue still persist :(

Currently battling with this same error on same Laravel 10 / Horizon setup and haven't been successful with the fix

fwilliamconceicao commented 7 months ago

I'm here using PHP 8.2 and Laravel 10 and this issue still persist :(

Currently battling with this same error on same Laravel 10 / Horizon setup and haven't been successful with the fix

After almost 1 year struggling with this, I just gave up and moved my jobs/queues to serverless applications with C#, Go and Rust 👍