Why should I close or keep Redis connections open?

后端 未结 2 1105
太阳男子
太阳男子 2021-01-19 12:03

I\'m using Redis in a PHP project. I use phpredis as a client. Sometimes, during long CLI-scripts, I experience PHP segmentation faults.

I\'ve experienced before tha

2条回答
  •  梦谈多话
    2021-01-19 12:13

    The answer to your question much depends on cases of redis usage in your application. So, should your never close a connection with idle connection timeout?

    In general no, your should keep it default - 0. Why or when:

    • Any types of long living application. Such as CLI-script ot background worker. Why - phpredis do not has builded in reconnection feature so your should take care about this by yourself or do not your idle timeout.
    • Each time your request processed or CLI script die - all connections would be closed by php engine. Redis server close all connection for closed client sockets. You will have no problems like zombie connection or something like that. As extension, phpredis close connection in destructor - so your may be sure connections don't stay open.

    p.s. Of course your can implement reconnection insome proxy class in php by yourself. We have redis in high load environment - ~4000 connections per second on instance. After 2.4 version we do not use idle connection timeout. And do not have any types of troubles with that.

提交回复
热议问题