From:             robert at interjinn dot com
Operating system: Linux version 2.4.19-16mdk
PHP version:      4.3.3
PHP Bug Type:     Filesystem function related
Bug description:  stream-set_blocking() causes unexpected non erroneous exit from 
script.

Description:
------------
When I use stream_set_blocking() to make the standard input file handle
non-blocking the script exits seemingly random. For example the $count
output can have a last printed value anywhere from 200 to 3000.

Reproduce code:
---------------
<?
  
    if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
    {                                                     
        echo 'Failed to open STDIN'."\n";
        exit();
    }          

    stream_set_blocking( $stdin, false );  
                                           
    $count = 0;                            
    while( 1 ) 
    {         
        echo 'Count: '.($count++)."\n";

        if( ($char = fread( $stdin, 1 )) != '' )
        {
            echo 'Char: '.$char."\n";
        }
        else
        {
            echo 'Fooo!'."\n";
        }
    }    


Expected result:
----------------
Script should run forever since it is in a while( 1 ) loop. This was done
on purpose for testing purposes. At each pass of the loop it should print
the current $count index, then if data exist in $stdin then it should
print the character, otherwise print Fooo! to the screen.

Actual result:
--------------
Script does not run forever. Script exits and the last count printed can
be anywhere from 200 to 3000 -- it seems kind of random. I ran the script
through gdb and gdb indicates that the program (PHP) exits properly. Thus
there is no backtrace to provide.

-- 
Edit bug report at http://bugs.php.net/?id=25616&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25616&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25616&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25616&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25616&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25616&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25616&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25616&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25616&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25616&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25616&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25616&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25616&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25616&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25616&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25616&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25616&r=float

Reply via email to