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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to