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?