|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-06-30 10:39 UTC] 452476865 at qq dot com
Description:
------------
stream_socket_shutdown don't close the TCP connection.
this cause TCP connection overflow when high concurrency on WEB server.
i think stream_socket_shutdown should close TCP connection, not just TIME_WAIT status.
Test script:
---------------
<?php
function one($host, $port){
$host = 'tcp://' . $host . ':' . $port;
$socket = @stream_socket_client(
$host,
$errorNumber,
$errorDescription,
ini_get("default_socket_timeout")
);
stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
}
$host = '192.168.2.243';
$port = 7000;
for($i=0; $i<100; $i++){
one($host, $port);
}
echo "done";
?>
Expected result:
----------------
netstat -an |grep '192.168.2.243'
return :
none
Actual result:
--------------
netstat -an |grep '192.168.2.243'
return :
tcp 0 0 192.168.2.66:57336 192.168.2.243:7000 TIME_WAIT
tcp 0 0 192.168.2.66:57282 192.168.2.243:7000 TIME_WAIT
tcp 0 0 192.168.2.66:57222 192.168.2.243:7000 TIME_WAIT
tcp 0 0 192.168.2.66:57298 192.168.2.243:7000 TIME_WAIT
tcp 0 0 192.168.2.66:57236 192.168.2.243:7000 TIME_WAIT
tcp 0 0 192.168.2.66:57318 192.168.2.243:7000 TIME_WAIT
tcp 0 0 192.168.2.66:57398 192.168.2.243:7000 TIME_WAIT
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 05:00:02 2025 UTC |
it's still at TIME_WAIT status using fclose with two method. method one========================== function connectRedis($host, $port){ $host = 'tcp://' . $host . ':' . $port; $socket = @stream_socket_client( $host, $errorNumber, $errorDescription, ini_get("default_socket_timeout") ); //stream_socket_shutdown($socket, STREAM_SHUT_RDWR); fclose($socket); } $host = '192.168.2.243'; $port = 7000; for($i=0; $i<100; $i++){ connectRedis($host, $port); } echo "done\r\n"; method two========================== function connectRedis($host, $port){ $host = 'tcp://' . $host . ':' . $port; $socket = @stream_socket_client( $host, $errorNumber, $errorDescription, ini_get("default_socket_timeout") ); stream_socket_shutdown($socket, STREAM_SHUT_RDWR); fclose($socket); } $host = '192.168.2.243'; $port = 7000; for($i=0; $i<100; $i++){ connectRedis($host, $port); } echo "done\r\n";