This example will demonstrate how to use an input stream, it will accept an input from the user, wait till user presses Enter key and then shall display the entered text.
<?php
$stdin = fopen('php://stdin', 'r');
echo "Please Enter your Name :";
$mystr = fgets($stdin,100);
echo "Your Name Is :\n";
echo $mystr;
fclose($stdin);
?>
The next example shows you how to output text to an error stream
<?php
$stderr = fopen('php://stderr', 'w');
fwrite($stderr,"There was an Error");
fclose($stderr);
?>
Ok before we move ahead there are few things we should know, the output to the error stream is always send to the error device (normally the screen) and is not sent to a file or another command when redirecting the output. Always make sure you close the stream once you are done with it. Please refer to PHP manual if you need more information on fopen, fwrite, fgets and fclose functions.