Bug #75283 [NEW]: Disconnection not detected by socket_read()
| From: | privacy dot and dot spam dot protection at gmx dot fr | Date: | Fri, 29 Sep 2017 09:55:03 +0000 |
| Subject: | Bug #75283 [NEW]: Disconnection not detected by socket_read() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-211448@lists.php.net to get a copy of this message | ||
From: privacy dot and dot spam dot protection at gmx dot fr
Operating system: Debian
PHP version: 7.0.24
Package: Sockets related
Bug Type: Bug
Bug description:Disconnection not detected by socket_read()
Description:
------------
According to documentation, an empty string ("") is returned by
socket_read() when there's no more data to read and false value on error
(including if the remote host has closed the connection).
However when socket_read has no data to read false is still returned.
So it's impossible to detect if connection has been reseted by pear.
Test script:
---------------
$co = false;
while (!$co) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket !== false) echo "OK 1.\n";
$result = socket_connect($socket, $address, $service_port);
if ($socket !== false) {
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"
=> 1, "usec" => 1));
echo "OK 2.\n";
$co = true;
}
}
while (true) {
socket_clear_error($socket);
$out = socket_read($socket, 2048);
$socket_last_error = socket_last_error($socket);
$strErr = socket_strerror($socket_last_error) . ' ' .
$socket_last_error;
echo date('Ymd H:i:s') . " : $strErr ($socket_last_error) => " .
var_export($out, true) . PHP_EOL;
}
Expected result:
----------------
OK 1.
Try connection '9.3.0.23' on port '30001'...
OK 2.
// client's connected on server
// no data have been sent by server
20170929 11:09:17 : Success 0 (0) => ''
20170929 11:09:18 : Success 0 (0) => ''
20170929 11:09:19 : Success 0 (0) => ''
//server send data
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
// no data have been sent by server
20170929 11:09:21 : Success 0 (0) => ''
20170929 11:09:22 : Success 0 (0) => ''
20170929 11:09:23 : Success 0 (0) => ''
// connection is reset by server
20170929 11:09:24 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:25 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:26 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:27 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:28 : Resource temporarily unavailable 11 (11) => false
Actual result:
--------------
OK 1.
Try connection '9.3.0.23' on port '30001'...
OK 2.
// client's connected on server
// no data have been sent by server
20170929 11:09:17 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:18 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:19 : Resource temporarily unavailable 11 (11) => false
//server send data
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
// no data have been sent by server
20170929 11:09:21 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:22 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:23 : Resource temporarily unavailable 11 (11) => false
// connection is reset by server
20170929 11:09:24 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:25 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:26 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:27 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:28 : Resource temporarily unavailable 11 (11) => false
--
Edit bug report at https://bugs.php.net/bug.php?id=75283&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75283&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75283&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75283&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75283&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75283&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75283&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75283&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75283&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75283&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75283&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75283&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75283&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75283&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75283&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75283&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75283&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75283&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75283&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75283&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75283&r=mysqlcfg