If you use a pipeline, you will need to buffer the input, rather than process it all at once, just go one line at a time, as is standard with * nix tools.
SheBang on top of the file allows you to directly execute the file, instead of calling php on the command line.
Save the following for test.php and run
cat test.php | ./test.php
to see the results.
#!php <?php $handle = fopen('php://stdin', 'r'); $count = 0; while(!feof($handle)) { $buffer = fgets($handle); echo $count++, ": ", $buffer; } fclose($handle);
source share