CodeIgniter Forums

Full Version: CI can't reuse redis connections
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a website built using CI, in which I use redis to store session data.

However, when the server frequently queries the session, there will be a lot of "TIME_WAIT" TCP connections. Then redis can not be connected. (Seems that the server is down.)

It seems that use socket instead of TCP could solve the problem. But I found that CI plans to support socket in version 3.1.0, which hasn't been released.

Besides switching to socket, are there any solution to this problem?
What connection is there to reuse? What do you mean by that? I don't really understand the problem that you're claiming to have.
(03-07-2016, 10:51 AM)Narf Wrote: [ -> ]What connection is there to reuse? What do you mean by that? I don't really understand the problem that you're claiming to have.

I mean to reuse the connection that CI has already established to redis server.
The problem is that we have to use `session_write_close` to temporarily release the session lock, and re-open it later, to optimize our application. (Actually it does work) But it causes a great number of short TCP connections to redis, which causes a lot of `TIME_WAIT` status and make Redis unable to connect.

Calling `session_write_close` seems the only way to release the lock. I can't simply release the lock but keep the TCP connection. If I can do keep it, that is what "reuse redis connection" means, I can avoid the problem, but I simply unable to do that. Another approach is to use UNIX socket instead of TCP, but it's Codeigniter's future feature and have not been released now.
(03-08-2016, 03:14 AM)roastduck Wrote: [ -> ]The problem is that we have to use `session_write_close` to temporarily release the session lock, and re-open it later, to optimize our application. (Actually it does work) But it causes a great number of short TCP connections to redis, which causes a lot of `TIME_WAIT` status and make Redis unable to connect.

Calling `session_write_close` seems the only way to release the lock. I can't simply release the lock but keep the TCP connection. If I can do keep it, that is what "reuse redis connection" means, I can avoid the problem, but I simply unable to do that. Another approach is to use UNIX socket instead of TCP, but it's Codeigniter's future feature and have not been released now.

You're not supposed to close and then re-start a session from within the same request.
(03-08-2016, 04:05 AM)Narf Wrote: [ -> ]
(03-08-2016, 03:14 AM)roastduck Wrote: [ -> ]The problem is that we have to use `session_write_close` to temporarily release the session lock, and re-open it later, to optimize our application. (Actually it does work) But it causes a great number of short TCP connections to redis, which causes a lot of `TIME_WAIT` status and make Redis unable to connect.

Calling `session_write_close` seems the only way to release the lock. I can't simply release the lock but keep the TCP connection. If I can do keep it, that is what "reuse redis connection" means, I can avoid the problem, but I simply unable to do that. Another approach is to use UNIX socket instead of TCP, but it's Codeigniter's future feature and have not been released now.

You're not supposed to close and then re-start a session from within the same request.

But consider the application below: I have a long poll, which keeps checking current status, such as if the user has a new mail, etc. It checks the session every 6 seconds. I have to release the lock just to let other threads able to use session.