Re: Problem with getting non-blocking data from stdin

From: Date: Sat, 20 Sep 2003 05:01:14 +0000
Subject: Re: Problem with getting non-blocking data from stdin
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-163271@lists.php.net to get a copy of this message
One more thing: gdb doesn't do a damned thing for debugging PHP scripts. Look for the errors and warnings output to the browser. (or tty if you're using /usr/bin/php). -Dan On Sat, 2003-09-20 at 00:33, Robert Cummings wrote: > 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 (#163271) next »