|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-09-16 20:27 UTC] Slig at free dot fr
Description:
------------
stream_select fails to return the number of modified descriptors.
The bug happen on linux amd64 (tested on a quad core xeon, debian etch amd64) but not on x86 install (tested on a similar computer but dual core xeon, debian etch x86).
It seems to happen only when php is built with openssl (i tried many combinaisons), with php 5.2.0, 5.2.1, 5.2.2, 5.2.3, 5.2.4, php5 snap, and also php6 snap.
This bug is the same as #40735 but I am unable to modify the status of
that bug.
I can eventually provide a ssh access to the computer further tests and debug (ask me by email).
Reproduce code:
---------------
<?php
// replace with your smtp ip if needed, need a tcp server which reply data immediatly
$handle = fsockopen('tcp://smtp',25);
while(!feof($handle)) {
$r = array($handle);
$w = null;
$e = array($handle);
$nb = stream_select($r,$w,$e,3);
echo "select : $nb, r=".count($r).', w='.count($w).', e='.count($e)."\n";
while($nb>0){
echo "Reading...\n";
$contents = fread($handle,8192);
echo "Contents: [$contents]\n";
$r = array($handle);
$w = null;
$e = array($handle);
$nb = stream_select($r,$w,$e,1);
echo "select : $nb, r=".count($r).', w='.count($w).', e='.count($e)."\n";
}
usleep(20000);
}
fclose($handle);
?>
Expected result:
----------------
select : 1, r=1, w=0, e=0
Reading...
Contents: [220 naxos2.unice.fr ESMTP Sendmail 8.13.1/8.13.1; Sun, 16 Sep 2007 22:23:04 +0200
]
select : 0, r=0, w=0, e=0
Actual result:
--------------
select : 0, r=1, w=0, e=0
select : 0, r=1, w=0, e=0
select : 0, r=1, w=0, e=0
select : 0, r=1, w=0, e=0
select : 0, r=1, w=0, e=0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 16:00:02 2025 UTC |
I tested today on a dual dual-core-xeon on current Fedora 7 x86_64, first with current php and current openssl, then building php6 from the source : same result, it give the expected result without openssl, but return 0 when build with --with-openssl when there is a descriptor to read. Note: If i use as workaround 'while($nb>0 || count($r)>0){' and reduce the read buffer ( fread($handle,30); for example), then i see that after the first read the value returned by stream_select is ok... but it shows another bug (#42720) :dI was hit by the same annoying bug (CentOS 4.5/x64/PHP5.1.6 & 5.2.3) After debugging PHP stream_select() I found out that system's select() returns correct number but this value get's mysteriously set to zero (memory is overwritten?) a few steps before returning it to PHP script. Anyway, the cure for me was to change an variable type from int to long and explicitly reset it to 0. This patch works for both PHP 5.1 and 5.2: --- ext/standard/streamsfuncs.c.orig 2007-10-09 16:21:30.000000000 +0300 +++ ext/standard/streamsfuncs.c 2007-10-09 16:21:41.000000000 +0300 @@ -608,7 +608,7 @@ zval **elem, **dest_elem; php_stream *stream; HashTable *new_hash; - int this_fd, ret = 0; + long this_fd = 0, ret = 0; if (Z_TYPE_P(stream_array) != IS_ARRAY) { return 0;