socket and TIME_WAIT issue
Posted: Sat Feb 28, 2004 1:50 am
Hello,
While working on a threaded tcp daemon I ran into a litlte snag. This daemon forks childrean for incoming connections. What I found was that after making many connections to the daemon I started to see a backlog of TIME_WAIT connections. I noticed that other applications also do this. When I stop the daemon any active children are killed which is done by using SIGUSR1. The connection goes from ESTABLISHED to TIME_WAIT with a 60 second interval. Because this timeout is in effect I cannot start the daemon again until all of these dead processes connections finally die.
After this child connection has been accepted this is the code that is ran:
I have tried keep_alive but it doesn't seem to help. Specifying a value of SO_REUSEADDR = 0 doesn't seem to do much either. I've notice that these TIME_WAIT connections occur under mysql and apache but when you stop the process they are killed. At first I though that the socket may have stayed open waiting for some data so I removed the original socket_read.
Is there something simple that I am missing?
While working on a threaded tcp daemon I ran into a litlte snag. This daemon forks childrean for incoming connections. What I found was that after making many connections to the daemon I started to see a backlog of TIME_WAIT connections. I noticed that other applications also do this. When I stop the daemon any active children are killed which is done by using SIGUSR1. The connection goes from ESTABLISHED to TIME_WAIT with a 60 second interval. Because this timeout is in effect I cannot start the daemon again until all of these dead processes connections finally die.
After this child connection has been accepted this is the code that is ran:
Code: Select all
<?php
socket_setopt($activesock->sock, SOL_SOCKET, SO_KEEPALIVE, 1);
//socket_setopt($activesock->sock, SOL_SOCKET, SO_REUSEADDR, 1);
socket_getpeername($activesock->sock, $activesock->clienthost, $activesock->clientport);
socket_write($activesock->sock, "hello $activesock->clienthost .\r\n");
socket_set_nonblock($activesock->sock);
socket_write($activesock->sock,"Hi Jack, I have to go now.\r\n");
// Do stuff loop to be implemented later
socket_close($activesock->sock);
unset($activesock->sock);
?>Is there something simple that I am missing?