STD IO Steams are generally used for CLI applications in PHP
The standard input is usually received from the keyboard
Standard out and standard error are usually sent to the screen
|Standard In||Input from Keyboard||stdin||0|
|Standard Out||Output to Screen||stdout||1|
|Standard Error||Output to Screen||stderr||2|
Read a single line from stdin using fgets(STDIN)
<?php //using the trim() function to remove any leading/trailing whitespace $line = trim(fgets(STDIN)); ?>
Assuming PHP is available from the command line, you can write to STDOUT using:
php -r 'fwrite( STDOUT, "some text output\n") ; '
note -r means to run the command
Or to write to STDERR:
php -r 'fwrite( STDERR, "some text output\n") ; '
Simple way to tell if PHP is running from the command line is to check the version with: