|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2012-08-14 13:25 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 21:00:02 2025 UTC | 
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); }