Shkarbatov Dmitriy Shkarbatov Dmitriy - 6 months ago 57
PHP Question

High traffic connection between Php and Redis

I have backend on php, that works with Redis.

But when requests increased and they more than 2000 request per sec I receive an error:

99 - Cannot assign requested address

All sockets in TIME_WAIT.

Connecting example:

$this->_socket = @stream_socket_client(
'tcp://' . $this->hostname . ':' . $this->port,

I find solution:

But /proc/sys/net/ipv4/tcp_tw_recycle I can't set in 1.
Don't want to loss packets on the network between application and redis.

Php on new request from API create a new socket.

Any ideas?


Fixed problem. Use tcp reuce and time waite for socket sets in 10 seconds. Php work with socket in persistent mode


So even in 2 000 request per second it use not more then 61 sockets.