php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74857 stream_socket_shutdown and fclose didn't close the TCP connection
Submitted: 2017-07-05 02:23 UTC Modified: 2017-07-05 05:48 UTC
From: 452476865 at qq dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.6.30 OS: ubuntu
Private report: No CVE-ID: None
 [2017-07-05 02:23 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-05 05:48 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-07-05 05:48 UTC] requinix@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC