Bug #64654 [Opn]: socket_select returns false and socket_last_error returns 0 (success)
Edit report at https://bugs.php.net/bug.php?id=64654&edit=1
ID: 64654
Updated by: laruence@php.net
Reported by: xilon dot jul at gmail dot com
Summary: socket_select returns false and socket_last_error
returns 0 (success)
Status: Open
Type: Bug
Package: Sockets related
Operating System: Linux 3.5.0-23-generic
PHP Version: 5.4.14
Block user comment: N
Private report: N
New Comment:
I don't think this is a bug.
the warning is threw before do really "select", it is an error in php side. not
system call side.
and socket_last_error is for the error in system call side.
Previous Comments:
------------------------------------------------------------------------
[2013-04-17 09:52:28] xilon dot jul at gmail dot com
Description:
------------
When a socket ressource previously watched for read I/O in socket_select is
closed, the socket_select function would return false and throw a warning saying
"Not a valid socket ressource".
The fact is that subsequent call to socket_last_error() returns 0 which translates
to success using socket_strerror().
Test script:
---------------
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (false === socket_bind($socket, '0.0.0.0', 5555)) {
die('bind()');
}
$read[] = $socket;
// voluntarily close the socket
socket_close($socket);
// Will throw a warning and return false
$retval = socket_select($read, $w = null, $e = null, 1);
echo socket_last_error(); // returns 0
Expected result:
----------------
As the C select system call, closing the socket should return a valid system error
code.
The C counterpart of this PHP sample above gives :
select(): Bad file descriptor (9 => EBADF)
Actual result:
--------------
The result of socket_last_error is 0.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64654&edit=1
Thread (7 messages)