Closed TorstenDittmann closed 3 years ago
IMO, persistent things make no sense for Swoole-like projects as the Swoole server is already persistent, it only benefits FPM projects. And connection pool can not work on FPM mode beacuse pool is not persistent...
We are using a Redis Connection from the ConnectionPool inside a WebSocket Worker and are losing connection to a subscribe
every 60 seconds using this configuration:
ini_set('default_socket_timeout', -1);
// ...
$pool = new RedisPool((new RedisConfig)
->withHost($redisHost)
->withPort($redisPort)
->withAuth($redisAuth)
->withDbIndex(0)
);
We have previously used a persistent connection and didn't run into this issue before - thats why this was my first guess to implement.
Just realized something - using the withReadTimeout
will fix the disconnects. Meaning if I set it to 120 - it will disconnect after 120 seconds.
Looking at the official phpredis documentation, having a read timeout of 0
should mean unlimited, which would solve my problem.
So as it looks like this is not a Swoole problem on the first glance 🤔
Fixed it with setting the option after getting a redis connection from the pool:
$redis->setOption(\Redis::OPT_READ_TIMEOUT, -1);
Looks like this is not possible on the connect
constructor of Redis.
You mean the read_timeout
paramter in connect()
did not work, why?
You mean the
read_timeout
paramter inconnect()
did not work, why?
Yes, it works with everything that is not 0
- just the unlimited timeout with passing 0
doesn't work.
After took a quick look at source code, I think doc of phpredis is wrong, when read_timeout
is zero, the connection will set read_timeout
to default_socket_timeout
.
I noticed that you have already set default_socket_timeout
to -1
, I still do not know why it do not work for you....
After took a quick look at source code, I think doc of phpredis is wrong, when
read_timeout
is zero, the connection will setread_timeout
todefault_socket_timeout
. I noticed that you have already setdefault_socket_timeout
to-1
, I still do not know why it do not work for you....
Confused as well. But it's not a problem with Swoole - so I think we are good here 🙂
RedisPool