NYCPHP Meetup

NYPHP.org

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

jon baer jonbaer at jonbaer.net
Tue Sep 23 09:13:56 EDT 2003


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
>




More information about the talk mailing list