Bug #74857 [Opn->Nab]: stream_socket_shutdown and fclose didn't close the TCP connection

From: Date: Wed, 05 Jul 2017 05:48:41 +0000
Subject: Bug #74857 [Opn->Nab]: stream_socket_shutdown and fclose didn't close the TCP connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209815@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74857&edit=1 ID: 74857 Updated by: requinix@php.net Reported by: 452476865 at qq dot com Summary: stream_socket_shutdown and fclose didn't close the TCP connection -Status: Open +Status: Not a bug Type: Bug Package: Streams related Operating System: ubuntu PHP Version: 5.6.30 Block user comment: N Private report: N New Comment: TIME_WAIT is a normal part of the TCP/IP socket lifecycle. Even if you close the socket, it is ultimately up to the OS to decide when to completely release it. https://www.google.com/search?q=ubuntu+time_wait Previous Comments: ------------------------------------------------------------------------ [2017-07-05 02:23:51] 452476865 at qq dot com Description: ------------ REF Bug Report: https://bugs.php.net/bug.php?id=74834 i test fclose() method ,but TCP connection still on TIME_WAIT status. Test script: --------------- ========================== 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); } ========================== 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); } 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74857&edit=1

« previous php.bugs (#209815) next »