Re: Problem with getting non-blocking data from stdin
| From: | Robert Cummings | Date: | Sat, 20 Sep 2003 05:48:21 +0000 |
| Subject: | Re: Problem with getting non-blocking data from stdin | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163275@lists.php.net to get a copy of this message | ||
On Sat, 2003-09-20 at 01:52, Curt Zirzow wrote:
> * Thus wrote Robert Cummings (robert@interjinn.com):
> > 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 );
>
> I believe this is not needed, stdin is nonblocking all the time.
My original test script didn't set the blocking state to non blocking. I
determined from that that stdin is initally in a blocking state. Since I
typed several characters and none where printed till I hit enter.
>
> >
> > $count = 0;
> > while( 1 )
>
> this will never exit until php runs out of memory, and most likely
> will lead to unexpected results.
Yeah, it was just a test script. But still, if the memory had been
exhausted, it wouldn't be in under a second, and I'd get a core dump
like I usually do when I have a runaway recursive function.
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. |
`------------------------------------------------------------'