stdin from a pipe

From: Date: Sat, 17 Jan 2004 11:33:01 +0000
Subject: stdin from a pipe
Groups: php.general 
Request: Send a blank email to php-general+get-174918@lists.php.net to get a copy of this message
hello, What is the better way to read from a pipe from a php cli script? #! /usr/bin/php -q <?php $stdin = fopen('php://stdin', 'r'); while (!feof($stdin)) $buffer .= fgets($stdin, 4096); fclose($stdin); ?> or <?php while ($stdin = fread(STDIN, 4096)) $buffer .= $stdin; ?> I have tryed these ways, but the problem is that if there is no pipe input, the script is waiting for ^D from the user (so this is a problem if the php filter is used in a bash script, because it will block the process). How can I detect if there is an stdin from a pipe or not? I have tryed this but it does not work: stream_set_timeout(STDIN, 1, 10); -- thanks

« previous php.general (#174918) next »