|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62816 stream_socket_accept can't block infinitely
Submitted: 2012-08-14 13:25 UTC Modified: 2012-08-14 18:55 UTC
Avg. Score:4.3 ± 0.9
Reproduced:9 of 9 (100.0%)
Same Version:2 (22.2%)
Same OS:3 (33.3%)
From: xrstf-misc at yahoo dot com Assigned:
Status: Open Package: Sockets related
PHP Version: 5.4.5 OS: Linux (ARM)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: xrstf-misc at yahoo dot com
New email:
PHP Version: OS:


 [2012-08-14 13:25 UTC] xrstf-misc at yahoo dot com
I'm opening a socket on, 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:

$addr   = "tcp://";
$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";

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

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-14 14:16 UTC] 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 
 [2012-08-14 17:10 UTC] xrstf-misc at yahoo dot com
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);
 [2012-08-14 18:55 UTC] xrstf-misc at yahoo dot com
-Summary: stream_socket_accept does not block +Summary: stream_socket_accept can't block infinitely
 [2012-08-14 18:55 UTC] xrstf-misc at yahoo dot com
(Changed bug title to better reflect the actual problem.)
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 14:01:31 2024 UTC