Bug #74834 [Nab]: stream_socket_shutdown don't work!
| From: | 452476865 at qq dot com | Date: | Mon, 03 Jul 2017 02:29:58 +0000 |
| Subject: | Bug #74834 [Nab]: stream_socket_shutdown don't work! | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209777@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74834&edit=1
ID: 74834
User updated by: 452476865 at qq dot com
Reported by: 452476865 at qq dot com
Summary: stream_socket_shutdown don't work!
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:
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";
Previous Comments:
------------------------------------------------------------------------
[2017-07-01 10:55:24] bwoebi@php.net
If you do not have a well-defined reason for not using fclose(), better use fclose() rather than
stream_socket_shutdown(STREAM_SHUT_RDWR).
It will remain in TIME_WAIT until you actually close the resource (and implicitly the file
descriptor beyond it).
------------------------------------------------------------------------
[2017-06-30 10:42:08] kelunik@php.net
No, stream_socket_shutdown doesn't close a connection, use fclose for that.
------------------------------------------------------------------------
[2017-06-30 10:39:21] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74834&edit=1