|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-01-02 01:27 UTC] chip at cyan dot com
All references to stream_select (an otherwise un-documented function) say that it is the same as socket_select.
With socket_select setting the 4th parameter (the timeout in seconds) to 0 would normaly make it wait for a change in the sockets forever(no timeout).
However with stream_select, if you set the 4th parameter to 0, it does not wait at all, instead returning right away. To create the desired effect you must set it equal to NULL.
Workaround:
Set the 4th parameter (seconds) to NULL
To Fix:
change line line 789 in
/ext/standard/file.c( as included in php 4.3.0 /* $Id: file.c,v 1.279.2.4 2002/12/26 22:36:21 wez Exp $ */) from:
if (sec != NULL) {
to:
if (sec != NULL && sec != 0) {
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 10:00:01 2025 UTC |
Please try this script; it works just fine here. The expected output is this: resource(4) of type (Socket) Testing timeout of 0 seconds Timeout after 0 seconds, n is 0 OK! Testing timeout of 5 seconds Timeout after 5 seconds, n is 0 OK! Please allow a good 10 seconds for this last part; it should never return; after more than 10 seconds, stop the script by pressing CTRL-C Testing timeout of infinite seconds <?php function timeout_test($s, $duration) { $t1 = time(); printf("Testing timeout of %s seconds\n", $duration === null ? "infinite" : $duration); $n = socket_select($r = array($s), $w = null, $e = null, $duration); $t2 = time(); $actual = $t2 - $t1; printf("Timeout after %d seconds, n is %d\n", $actual, $n); if ($actual != $duration) { echo "---> FAILED? (although a small difference is allowed!)\n"; } else { echo "OK!\n"; } echo "\n"; } $s = socket_create(AF_INET, SOCK_STREAM, 0); var_dump($s); timeout_test($s, 0); timeout_test($s, 5); echo "Please allow a good 10 seconds for this last part; it should never\n"; echo "return; after more than 10 seconds, stop the script by pressing CTRL-C\n"; timeout_test($s, null); ?>Please use that script and not the previous one: <?php function timeout_test($s, $duration) { $t1 = time(); printf("Testing timeout of %s seconds\n", $duration === null ? "infinite" : $duration); $n = socket_select($r = array($s), $w = null, $e = null, $duration); $t2 = time(); $actual = $t2 - $t1; printf("Timeout after %d seconds, n is %d\n", $actual, $n); if ($actual != $duration) { echo "---> FAILED? (although a small difference is allowed!)\n"; } else { echo "OK!\n"; } echo "\n"; } $s = socket_create(AF_INET, SOCK_STREAM, 0); var_dump($s); socket_bind($s, "localhost", 14450); socket_listen($s); timeout_test($s, 0); timeout_test($s, 5); timeout_test($s, null); ?>