NYCPHP Meetup

NYPHP.org

[nycphp-talk] determining empty STDIN | php://stdin (cli)

jon baer jonbaer at jonbaer.net
Tue Sep 23 10:07:04 EDT 2003


unfortunatley that failed as well ... here is a simple example:

<?php
 stream_set_timeout(STDIN, 3);
 $in = fgets(STDIN);
 echo $in;
?>

i was expecting this to bail out and print nothing after 3 seconds ...

- jon

----- Original Message ----- 
From: "Tim Gales" <tgales at tgaconnect.com>
To: "'NYPHP Talk'" <talk at lists.nyphp.org>
Sent: Tuesday, September 23, 2003 9:52 AM
Subject: RE: [nycphp-talk] determining empty STDIN | php://stdin (cli)


Jon,

I remembered seeing something about stream timeouts at
php.net 

I was curious so I looked it up:

bool stream_set_timeout ( resource stream, int seconds [,
int microseconds])


Sets the timeout value on stream, expressed in the sum of
seconds and microseconds. 


Note: As of PHP 4.3, this function can (potentially) work on
any kind of stream. In PHP 4.3, socket based streams are
still the only kind supported in the PHP core, although
streams from other extensions may support this function. 

I don't know if this is any help -- but it might be.


T. Gales & Associates
Helping People Connect with Technology
http://www.tgaconnect.com

-----Original Message-----
From: talk-bounces at lists.nyphp.org
[mailto:talk-bounces at lists.nyphp.org] On Behalf Of jon baer
Sent: Tuesday, September 23, 2003 9:48 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] determining empty STDIN |
php://stdin (cli)

ok after further investigation i realized i should have
worded my question
differently but in a nutshell:

this requires process control functions for setting a
timeout to not wait
for STDIN (otherwise user needs to type something first) in
turn these
functions are not available on Windoze.  so just to clarify
my question -
"on W32 there is no way to timeout STDIN from cli?"

- jon

----- Original Message -----
From: "jon baer" <jonbaer at jonbaer.net>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Tuesday, September 23, 2003 9:13 AM
Subject: Re: [nycphp-talk] determining empty STDIN |
php://stdin (cli)


> that was more or less what I had come up with but I had
noticed that
passing
> say an argument for reading php://stdin when there was no
content would
just
> hang.  So if someone did:
> php blah.php blah
> -instead of-
> cat <file> | php blah.php blah
> the feof is never read, im trying to determine if it has
to do with the
> option 'auto_detect_line_endings'
>
> - jon
>
> ----- Original Message -----
> From: "Analysis & Solutions"
<danielc at analysisandsolutions.com>
> To: "NYPHP Talk" <talk at lists.nyphp.org>
> Sent: Monday, September 22, 2003 10:54 PM
> Subject: Re: [nycphp-talk] determining empty STDIN |
php://stdin (cli)
>
>
> > Hi Jon:
> >
> > On Mon, Sep 22, 2003 at 01:33:42PM -0400, jon baer
wrote:
> > > normally the small scripts i write either getopt for
it's content or
> read
> > > STDIN along the pipe, but i just tried to throw in a
usage() function
> for
> > > null input and could not determine if STDIN was empty
or not it, just
> hangs
> > > (W32).
> > >
> > > ie:
> > > $d = fread(STDIN, 1024);
> > >
> > > nothing seems to be able to determine if there is
content ... any
ideas?
> > > have not tried on debian yet.  thought checking
(STDIN) would work but
> > > didn't.
> >
> > I'm confused as to what you're really after.  Wouldn't a
usage example
> > apply to tips on passing arguments to a command line
script?  Arguments
> > for such scripts are found in $_SERVER['argv'], not
STDIN.
> >
> > As far as STDIN goes, I'm used to reading it via fopen()
then fgets().
> >
> > So, a quick and dirty example...
> >
> >
> > if ( empty($_SERVER['argv'][1]) ) {
> >     $_SERVER['argv'][1] = '';
> > }
> >
> > switch ($_SERVER['argv'][1]) {
> >     case 'blah':
> >         $In = fopen('php://stdin', 'r');
> >
> >         while ( !feof($In) ) {
> >            // do blah
> >         }
> >         break;
> >
> >     default:
> >         echo 'usage...';
> > }
> >
> > Enjoy,
> >
> > --Dan
> >
> > --
> >      FREE scripts that make web and database programming
easier
> >            http://www.analysisandsolutions.com/software/
> >  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C
O M P A N Y
> >  4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f:
718-854-0409
> > _______________________________________________
> > talk mailing list
> > talk at lists.nyphp.org
> > http://lists.nyphp.org/mailman/listinfo/talk
> >
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>

_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk

_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk





More information about the talk mailing list