I am working on a site that connects to many URLs at the same time (we hope to get to ~ 600 per minute), and no matter what I try, there are always thousands of TIME_WAIT that are still open. I understand that they are important for TCP connections, but they use all available ports. PHP does not have SO_REUSEPORT, and SO_REUSEADDR does not work with remote connections. Here is the beginning of the code:
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($s, SOL_SOCKET, SO_LINGER,array('l_linger'=>0, 'l_onoff'=>0));
socket_set_option($s, SOL_SOCKET, SO_RCVTIMEO,array('sec'=>0,'usec'=>500000));
socket_set_option($s, SOL_SOCKET, SO_SNDTIMEO,array('sec'=>0,'usec'=>500000));
socket_set_option($s, SOL_SOCKET, SO_KEEPALIVE,0);
socket_set_option($s, SOL_SOCKET, SO_REUSEADDR,1);
socket_set_nonblock($s);
socket_bind($s,$ip,0);
socket_connect($s,$host,$port);
$ s goes into an array containing all the pending writes; after the write, we call socket_shutdown ($ s, 1); to close the record on the socket. Then after reading we:
socket_shutdown($s,2); socket_close($s);
while, 12 , , URL- . socket_select 0.
- ? , TIME_WAIT, netstat.
,