Edit report at https://bugs.php.net/bug.php?id=62816&edit=1

 ID:                 62816
 User updated by:    xrstf-misc at yahoo dot com
 Reported by:        xrstf-misc at yahoo dot com
 Summary:            stream_socket_accept does not block
 Status:             Open
 Type:               Bug
 Package:            Sockets related
 Operating System:   Linux (ARM)
 PHP Version:        5.4.5
 Block user comment: N
 Private report:     N

 New Comment:

When doing a select() call before accepting, using an infinite timeout works. 
Seems like select() correctly handles NULL as "no timeout".

So I can do (pseudocode):

if (1 === select(array($myListeningSocket), null, null, null /* <- timeout */)) 
{
    $conn = accept($myListeningSocket);
}


Previous Comments:
------------------------------------------------------------------------
[2012-08-14 14:16:42] xrstf-misc at yahoo dot com

Oddly enough, using the "raw" socket functions works as expected.

Test code:
----------
$socket = socket_create_listen($port); // instead of stream_socket_server
$conn   = socket_accept($socket);      // instead of stream_socket_accept

Maybe there is something wrong with the timeout handling in the stream related 
functions?

------------------------------------------------------------------------
[2012-08-14 13:25:02] xrstf-misc at yahoo dot com

Description:
------------
I'm opening a socket on 0.0.0.0, port 8080 (doesn't matter) and then I'm trying 
to accept incoming connections. For this, the stream_socket_accept() function 
should block and wait for connections.

This works on Windows and Linux (x86), but on ARM it fails. For some reason, 
the 
functions returns immediately, generating a warning:

  stream_socket_accept(): accept failed: Connection timed out

Setting the timeout in my testscript to 0 doesn't change anything. Setting the 
timeout to a non-infinite one like 10 seconds makes the function block 
correctly 
for 10 seconds.

The problem occurs in all PHP 5.4 versions. I didn't test 5.3 or earlier.

Test script:
---------------
<?php

$addr   = "tcp://0.0.0.0:8080";
$errno  = null;
$errstr = null;

print "\n";
print "  > Creating socket @ $addr...";
$socket = stream_socket_server($addr, $errno, $errstr);

if ($socket === false) {
    print " ERROR: $errstr ($errno)\n\n";
    exit(2);
}

print " OK :)\n";
print "  > Accepting incoming connections (listening)...";
$conn = stream_socket_accept($socket, -1);
print "    ERROR: should not have reached this point!\n\n";
exit(1);

Expected result:
----------------
The script should stop and wait at the stream_socket_accept() call forever.

Actual result:
--------------
The function returns false and throws a warning.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62816&edit=1

Reply via email to