php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63099 stream_socket_accept does not respect float seconds
Submitted: 2012-09-16 14:43 UTC Modified: 2012-09-16 14:59 UTC
From: prggmr at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.4.7 OS: Mac OSX/Unix
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: prggmr at gmail dot com
New email:
PHP Version: OS:

 

 [2012-09-16 14:43 UTC] prggmr at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.stream-socket-accept#refsect1-
function.stream-socket-accept-description
---
stream_socket_accept does not properly timeout given a floated time under 0 
seconds.

The documentation states it does accept a float and should be given in seconds, 
so a timeout such as .0010 should be valid and used.

Test script:
---------------
/**
 * Stream socket accept does not accept floats as documented
 */
function milliseconds(/* ... */) {
    return round(microtime(true) * 1000);
}
$socket = stream_socket_server('tcp://127.0.0.1:5000', $errno, $errstr);
stream_set_blocking($socket, 0);
echo "START TIME".PHP_EOL;
echo milliseconds().PHP_EOL;
while(false !== $connect = @stream_socket_accept($socket, .0010)) {
}
echo "END TIME".PHP_EOL;
echo milliseconds().PHP_EOL;
echo "START TIME".PHP_EOL;
echo milliseconds().PHP_EOL;
usleep(10 * 1000);
echo "END TIME".PHP_EOL;
echo milliseconds().PHP_EOL;

Expected result:
----------------
START TIME
1347806197759
END TIME
1347806197769
START TIME
1347806197760
END TIME
1347806197770

Actual result:
--------------
START TIME
1347806197759
END TIME
1347806197760
START TIME
1347806197760
END TIME
1347806197770

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-16 14:55 UTC] prggmr at gmail dot com
-Status: Open +Status: Closed
 [2012-09-16 14:55 UTC] prggmr at gmail dot com
Disregard .. my math was wrong :)
 [2012-09-16 14:59 UTC] rasmus@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC