#28141 [NEW]: sokcet_read return type: false vs ""
From: php at richardneill dot org
Operating system: Linux
PHP version: 5.0.0RC1
PHP Bug Type: Sockets related
Bug description: sokcet_read return type: false vs ""
Description:
------------
According to the documentation, socket_read() can return:
1)A string - normal data
2)An empty string "" - the other end closed the connection
3)false - something went wrong.
But it seems to be returning false on connection close.
Reproduce code:
---------------
$buffer=socket_read($socket,2048,PHP_NORMAL_READ);
if ($buffer===false){
echo "Error: socket_read() failed: reason:
".socket_strerror(socket_last_error())." \n";
exit (1);
}elseif ($buffer==''){
echo "Socket $socket returned an empty string. Closing connection\n";
socket_close($socket);
}else{
echo "Received data".trim($buffer)."\n";
}
Expected result:
----------------
I'm using netcat as a client, and then killing the netcat process with
Ctrl-C to simulate remote host disconnecting.
I expect to see the socket close.
Actual result:
--------------
Actually, the php script exits, because socket_read returns
false instead of "".
This may be a bug in the documentation for socket_read, rather than in its
behaviour.
Thanks for your help - Richard
--
Edit bug report at http://bugs.php.net/?id=28141&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28141&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28141&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28141&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28141&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28141&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28141&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28141&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28141&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28141&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28141&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28141&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28141&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28141&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28141&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28141&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28141&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28141&r=float
Thread (11 messages)
- php at richardneill dot org
- php at richardneill dot org#28141 [Opn]: socket_read return type: false vs ""
- andrey@php.net#28141 [Opn->Fbk]: socket_read return type: false vs ""
- php2 at richardneill dot org#28141 [Com]: socket_read return type: false vs ""
- php-bugs at lists dot php dot net#28141 [Fbk->NoF]: socket_read return type: false vs ""
- php at richardneill dot org#28141 [NoF->Opn]: socket_read return type: false vs ""
- php at hristov dot com#28141 [Com]: socket_read return type: false vs ""
- andrey@php.net#28141 [Opn->Asn]: socket_read return type: false vs "", when PHP_NORMAL_READ
- cyberlot at cyberlot dot net#28141 [Com]: socket_read return type: false vs "", when PHP_NORMAL_READ
- sniper@php.net#28141 [Asn->Bgs]: socket_read return type: false vs "", when PHP_NORMAL_READ
- php at richardneill dot org#28141 [Bgs]: socket_read return type: false vs "", when PHP_NORMAL_READ