Read from STDIN only if data passed to STDIN
Posted: Thu Nov 01, 2007 10:06 am
I'd like to read from stdin, only if data is present. So that I can make......do something different from...
If I use file_get_contents('php://stdin') the shell starts taking input if nothing is piped. I don't seem to be able to use filesize() or anything like that to tell how much data there is without causing the shell to start taking input. fpeek() would probably do the trick, if it existed.
Code: Select all
# php myscript.phpCode: Select all
# cat somefile | php myscript.php