PHP Redis Error: Uncaught exception ‘RedisException’
Asked Answered
P

3

8

I use Redis to build a IOS SNS App (for restful api). As more user use it, errors happened.

It throws out :

Uncaught exception 'RedisException' with message 'read error on connection' 
in /data1/www/htdocs/11/iossns/Model/Core/Redis.php

I don't know how to solve the problem.

Can you help?

Thank you!

Purse answered 10/4, 2012 at 6:38 Comment(2)
Check the Redis instance is running and you can connect with redis-cli (i.e. not from php).Meredith
Where is your code ?? they one you are using to connect to Redis ???Paracelsus
W
1

What PHP-to-Redis library are you using? Here’s the official list from Redis. What is your webserver? (Apache, nginx, etc) How is PHP running? (CGI, FPM, mod_php, etc)

Here’s a thread for the same exception message in phpredis. It turns out phpredis does not currently support persistent connections with php-fpm. Version 2.2.3 of phpredis has some connection handling changes that might decrease the frequency of your issues.

I recommend checking your Redis connector configuration to…

  1. disable persistent connections
  2. enable connection retries
  3. increase log verbosity

You might also consider adjustments to (generally increasing) default_socket_timeout in php.ini.

Walloping answered 4/8, 2013 at 9:6 Comment(1)
Updated link to list: redis.io/docs/clients/#phpPretermit
A
0

It's a redis 6 bug.

You can do this:

sudo nano /etc/systemd/system/redis.service

# ADD THIS TO [Service] SECTION

ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"

sudo systemctl daemon-reload && sudo systemctl restart redis-server
Apogamy answered 31/8, 2022 at 7:24 Comment(0)
S
-1

In my case in Ubuntu 20.04 I discovered systemctl was trying to restart service because it couldn't find the /run/redis/redis-server.pid redis-server.service: Failed with result 'timeout'.

Feb 25 17:51:09 artamredis systemd[1]: Failed to start Advanced key-value store.
Feb 25 17:51:09 artamredis systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 18.
Feb 25 17:51:09 artamredis systemd[1]: Stopped Advanced key-value store.
Feb 25 17:51:09 artamredis systemd[1]: Starting Advanced key-value store...
Feb 25 17:51:09 artamredis systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Operation not permitted

In order to solve it in /etc/redis/redis.conf file find

pidfile /var/run/redis_6379.pid

and change to

pidfile /run/redis/redis-server.pid
Sherellsherer answered 25/2, 2021 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.