|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-09-20 17:23 UTC] robert at interjinn dot com
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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 05:00:01 2025 UTC |
I have downloaded and compiled the PHP package located at http://snaps.php.net/php4-STABLE-latest.tar.gz When I ran the script I got the same result as before. It still exits successfully when it should be in an infinite loop.