|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25616 stream-set_blocking() causes unexpected non erroneous exit from script.
Submitted: 2003-09-20 17:23 UTC Modified: 2003-09-24 17:25 UTC
From: robert at interjinn dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.3 OS: Linux version 2.4.19-16mdk
Private report: No CVE-ID: None
 [2003-09-20 17:23 UTC] robert at interjinn dot com
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";

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

        if( ($char = fread( $stdin, 1 )) != '' )
            echo 'Char: '.$char."\n";
            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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-21 01:08 UTC] robert at interjinn dot com
I have downloaded and compiled the PHP package located at

When I ran the script I got the same result as before. It still exits successfully when it should be in an infinite loop.
 [2003-09-21 02:44 UTC]
Works fine for me..I let your script run for few minutes and it works just as expected.

Try running it without any php.ini loaded, like this:

# php -n test.php

(-n will make PHP not load any php.ini)

 [2003-09-21 10:22 UTC] robert at interjinn dot com
I just ran it with the -n flag and no change. Still exits seemingly randomly :(
 [2003-09-24 17:25 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

dupe of bug #25575
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Dec 07 18:01:29 2023 UTC