Problem with getting non-blocking data from stdin

From: Date: Sat, 20 Sep 2003 04:33:18 +0000
Subject: Problem with getting non-blocking data from stdin
Groups: php.general 
Request: Send a blank email to php-general+get-163267@lists.php.net to get a copy of this message
I wanted t play around with the CGI (not CLI) version of PHP and get a feel for the I/O stuff, specifically STDIN. So I whipped up the following script: /////////////////////////////////////////////////////////////////// #!/usr/bin/php -qC <? if( ($stdin = fopen( 'php://stdin', 'r' )) === false ) { echo 'Failed to open STDIN'."\n"; exit(); } stream_set_blocking( $stdin, false ); $count = 0; while( 1 ) { echo 'Foo: '.($count++)."\n"; if( ($char = fread( $stdin, 1 )) !== false ) { echo $char."\n"; } else { echo 'Fooo!'."\n"; } } //////////////////////////////////////////////////////////////////// Simple enough right?! The problem is the program exits seemingly randomly. The last value for $foo can be anywhere from 400 to 1500. Even more strange is that running it through gdb indicates a successful exit, with no problems or core dumps. Anyone had any similar experiences? I'm running PHP 4.3.3 (cgi) -- the latest download version. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#163267) next »