Input/output streams
Input/output streams
Input/output streams
The CLI SAPI defines a
few constants for I/O streams to make programming for the command
line a bit easier.
Constant | Description |
---|---|
STDIN |
An already opened stream to stdin. This <?php If you want to read single line from stdin, you can use <?php |
STDOUT |
An already opened stream to stdout. This <?php |
STDERR |
An already opened stream to stderr. This <?php |
Given the above, you don’t need to open e.g. a
stream for stderr yourself but simply use the constant
instead of the stream resource:
php -r 'fwrite(STDERR, "stderr\n");'
You do not need to explicitly close these streams, as they are
closed automatically by PHP when your script ends.
Note:
These constants are not available if reading the
PHP script from stdin.